87 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-09-26 11:20:08 -07:00
import {ProtoRecord, Record} from './record';
import {FIELD} from 'facade/lang';
2014-09-26 11:20:08 -07:00
export class ProtoWatchGroup {
@FIELD('final headRecord:ProtoRecord')
@FIELD('final tailRecord:ProtoRecord')
2014-09-26 11:20:08 -07:00
constructor() {
this.headRecord = null;
this.tailRecord = null;
2014-09-26 11:20:08 -07:00
}
2014-09-30 15:50:20 -07:00
/**
* Parses [expression] into [ProtoRecord]s and adds them to [ProtoWatchGroup].
*
* @param expression The expression to watch
* @param memento an opeque object which will be bassed to WatchGroupDispatcher on
* detecting a change.
* @param shallow Should collections be shallow watched
*/
2014-09-26 11:20:08 -07:00
watch(
expression:String,
2014-09-30 15:50:20 -07:00
memento,
{shallow/*=false*/}:{shallow:bool})
2014-09-26 11:20:08 -07:00
{
2014-09-30 15:50:20 -07:00
/// IMPLEMENT
2014-09-26 11:20:08 -07:00
}
instantiate(dispatcher:WatchGroupDispatcher):WatchGroup {
var watchGroup:WatchGroup = new WatchGroup(this, dispatcher);
var head:Record = null;
var tail:Record = null;
var proto:ProtoRecord = this.headRecord;
2014-09-26 11:20:08 -07:00
while(proto != null) {
tail = proto.instantiate(watchGroup);
if (head == null) head = tail;
proto = proto.next;
}
proto = this.headRecord;
2014-09-26 11:20:08 -07:00
while(proto != null) {
2014-09-28 16:29:11 -07:00
proto.instantiateComplete();
proto = proto.next;
2014-09-26 11:20:08 -07:00
}
watchGroup.headRecord = head;
watchGroup.tailRecord = tail;
2014-09-26 11:20:08 -07:00
return watchGroup;
}
2014-09-30 15:50:20 -07:00
2014-09-26 11:20:08 -07:00
}
export class WatchGroup {
2014-09-26 11:20:08 -07:00
@FIELD('final protoWatchGroup:ProtoWatchGroup')
@FIELD('final dispatcher:WatchGroupDispatcher')
@FIELD('final headRecord:Record')
@FIELD('final tailRecord:Record')
2014-09-26 11:20:08 -07:00
constructor(protoWatchGroup:ProtoWatchGroup, dispatcher:WatchGroupDispatcher) {
this.protoWatchGroup = protoWatchGroup;
this.dispatcher = dispatcher;
this.headRecord = null;
this.tailRecord = null;
2014-09-26 11:20:08 -07:00
}
insertChildGroup(newChild:WatchGroup, insertAfter:WatchGroup) {
/// IMPLEMENT
}
remove() {
/// IMPLEMENT
}
2014-09-30 16:39:37 -07:00
/**
* Sets the context (the object) on which the change detection expressions will
* dereference themselves on. Since the WatchGroup can be reused the context
* can be re-set many times during the lifetime of the WatchGroup.
*
* @param context the new context for change dection for the curren WatchGroup
*/
setContext(context) {
}
2014-09-26 11:20:08 -07:00
}
2014-09-28 16:29:11 -07:00
export class WatchGroupDispatcher {
onRecordChange(record:Record, context) {}
}