Created
September 5, 2013 03:25
-
-
Save nakosung/6445719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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