Skip to content

Instantly share code, notes, and snippets.

@nakosung
Created September 5, 2013 03:25
Show Gist options
  • Save nakosung/6445719 to your computer and use it in GitHub Desktop.
Save nakosung/6445719 to your computer and use it in GitHub Desktop.
templ = {
"type" : "Layer",
"controller" : "MyLayerCtrl",
{
"type" : "LabelTTF",
"repeat" : "x in friends",
"text" : "{{this.x}}",
"click" : "this.invite(this.x);"
}
}
root-scope, children/scope, repeat/scope
parent_scope = { x : 'main' }
child_scope = {}
child_scope.prototype = parent_scope
scope.$$watches = [
{
'target' : function,
'listener' : function,
}
]
$scope.$watch = (target,listener) ->
$scope.$$watches.push
target:(new Function(target)).bind($scope),
listener:listener
prev:null
$scope.$apply = (fn) ->
fn?()
__apply()
__apply = ->
while (inner_apply $rootScope) {}
inner_apply = ($scope) ->
changed = false
$scope.$$watches.forEach (w) ->
cur = w.target()
if w.prev != cur
w.listener.call($scope,cur,w.prev)
w.prev = cur
changed = true
_.reduce $scope.$$childScopes, ((s,memo) -> inner_apply(s) or memo), changed
child_scope.x
fn = new Function(Coffeescript.compile(a.text)) "@x" --> "this.x"
fn.call(scope)
controllers = {
"MyLayerCtrl" : ($scope) ->
$scope.friends = [ 'abc', 'def', 'ghi' ]
$scope.invite = (x) ->
my_dnode_function x
$scope.$watch 'xxx', (cur,prev) ->
xxx
dnode
on_datA_recv : (d) ->
$scope.$apply ->
$scope.data = d
}
ccdom templ, scope, controllers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment