Add singleton feature to Actor observation

This commit is contained in:
Tony Garnock-Jones 2014-08-25 11:44:09 -07:00
parent c5f7e9db2a
commit d080494664
1 changed files with 5 additions and 0 deletions

View File

@ -86,6 +86,7 @@ var observerDefaults = {
when: function () { return true; },
presence: null,
name: null,
singleton: null,
set: null,
added: null,
removed: null
@ -124,6 +125,7 @@ function finalizeActor(behavior, chunks) {
if (chunk.kind === 'observer') {
if (chunk.options.presence) { this[chunk.options.presence] = false; }
if (chunk.options.name) { this[chunk.options.name] = []; }
if (chunk.options.singleton) { this[chunk.options.singleton] = undefined; }
if (chunk.options.added) { this[chunk.options.added] = []; }
if (chunk.options.removed) { this[chunk.options.removed] = []; }
}
@ -220,6 +222,9 @@ function finalizeActor(behavior, chunks) {
if (chunk.options.name) {
this[chunk.options.name] = objs;
}
if (chunk.options.singleton) {
this[chunk.options.singleton] = objs.length === 1 ? objs[0] : undefined;
}
if (chunk.options.added || chunk.options.removed) {
var objSet = Route.arrayToSet(objs);