From d080494664c23fa1520a11817885098a5801f7cb Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 25 Aug 2014 11:44:09 -0700 Subject: [PATCH] Add singleton feature to Actor observation --- src/actor.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/actor.js b/src/actor.js index 7d691bf..2d0de4d 100644 --- a/src/actor.js +++ b/src/actor.js @@ -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);