-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyang-react.coffee
More file actions
31 lines (28 loc) · 898 Bytes
/
yang-react.coffee
File metadata and controls
31 lines (28 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Yang = require 'yang-js'
React = require 'react'
module.exports = (require './yang-react.yang').bind {
'extension(component)': ->
global: true
scope:
action: '0..n'
container: '0..n'
resolve: ->
@extends [ 'render' ].map (x) =>
unless @locate("action(#{x})")?
@constructor.parse "action #{x};"
@extends [ 'props', 'state' ].map (x) =>
unless @locate("container(#{x})")?
@constructor.parse "container #{x};"
construct: (data, ctx) ->
@debug "making React.Component class"
schema = this
component = class extends React.Component
constructor: (props) ->
super
@state = {}
schema.apply this
for own k, v of this when v instanceof Function
@[k] = v.bind this
component.prototype[k] = v for k, v of @apply(data)
return component
}