forked from angular/angular
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(change detection): implement barebone ChangeDetector
fixes angular#39
- Loading branch information
Showing
9 changed files
with
213 additions
and
158 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {ProtoWatchGroup, WatchGroup} from './watch_group'; | ||
import {ProtoRecord, Record} from './record'; | ||
import {FIELD, int} from 'facade/lang'; | ||
export * from './record'; | ||
export * from './watch_group' | ||
|
||
export class ChangeDetector { | ||
|
||
@FIELD('final _rootWatchGroup:WatchGroup') | ||
constructor(watchGroup:WatchGroup) { | ||
this._rootWatchGroup = watchGroup; | ||
} | ||
|
||
detectChanges():int { | ||
var record:Record = this._rootWatchGroup.headRecord; | ||
var count:int = 0; | ||
for (record = this._rootWatchGroup.headRecord; | ||
record != null; | ||
record = record.checkNext) { | ||
if (record.check()) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
library change_detection.facade; | ||
|
||
@MirrorsUsed(targets: const [FieldGetterFactory], metaTargets: const [] ) | ||
import 'dart:mirrors'; | ||
|
||
typedef SetterFn(Object obj, value); | ||
|
||
class FieldGetterFactory { | ||
getter(Object object, String name) { | ||
Symbol symbol = new Symbol(name); | ||
InstanceMirror instanceMirror = reflect(object); | ||
return (Object object) => instanceMirror.getField(symbol).reflectee; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export var SetterFn = Function; | ||
|
||
export class FieldGetterFactory { | ||
getter(object, name:string) { | ||
return new Function('o', 'return o["' + name + '"]'); | ||
} | ||
} |
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
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
Oops, something went wrong.