Migration from 0.10 to 0.11¶
Controllers¶
<div al-controller="main"></div>
alight.controllers.main = function(scope) {};
<div ctrl-main></div>
alight.ctrl.main = function(scope, cd) {};
alight.ctrl.main = {
scope: true,
link: function(scope, cd) {
scope.$parent // parent scope
}
};
Directives¶
alight.directives.al.test = function(element, value, scope, env) {};
alight.directives.al.test = {
scope: true, // true / 'isolate' / 'root'
link: function(element, value, scope, env) {}
}
alight.directives.al.test = function(scope, cd, element, value, env) {};
alight.directives.al.test = {
scope: true, // it make a new clean scope (object)
ChangeDetector: true // true / 'root'
link: function(scope, cd, element, value, env) {}
}
Scope¶
Scope - it was a mix of change detector and user’s data, in v0.11 Scope was devided to ChangeDetector and scope={} (user’s data), it gives different advatages.
scope = alight.Scope()
scope.name = 'linux'
scope.$watch('name', function(value) {
}, {
init: true // it calls the callback immediately
})
scope.$scan()
scope.$destroy()
scope = {
name: 'linux'
}
cd = alight.ChangeDetector scope
// now cd.scope === scope
cd.watch('name', function(value) {});
// you don't need set 'init' anymore, the callback is executed on finish binding process, also you can call cd.scan() for this.
cd.scan()
cd.destroy()