From 51afb50a6b5c80d0c915ae21bf9ad2b8335744b3 Mon Sep 17 00:00:00 2001 From: Bill Keese Date: Wed, 31 Dec 2014 09:20:13 +0900 Subject: [PATCH] Make notifyCurrentValue() take variable number of arguments. Fixes #14. --- Stateful.js | 10 ++++++---- tests/unit/Stateful.js | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Stateful.js b/Stateful.js index 8c2747e..88fc352 100644 --- a/Stateful.js +++ b/Stateful.js @@ -204,13 +204,15 @@ define([ }, /** - * Notify current value to observers. + * Notify current values to observers for specified property name(s). * Handy to manually schedule invocation of observer callbacks when there is no change in value. * @method module:decor/Stateful#notifyCurrentValue - * @param {string} name The property name. + * @param {...string} name The property name. */ - notifyCurrentValue: function (name) { - notify(this, name, this[propNames(name).p]); + notifyCurrentValue: function () { + Array.prototype.forEach.call(arguments, function (name) { + notify(this, name, this[propNames(name).p]); + }, this); }, /** diff --git a/tests/unit/Stateful.js b/tests/unit/Stateful.js index 3da544d..2c0f7bb 100644 --- a/tests/unit/Stateful.js +++ b/tests/unit/Stateful.js @@ -328,14 +328,19 @@ define([ "notifyCurrentValue()": function () { var dfd = this.async(1000), stateful = new (dcl(Stateful, { - foo: undefined + foo: undefined, + bar: undefined, + zaz: undefined }))({ - foo: "Foo" + foo: "Foo", + bar: "Bar", + zaz: "Zaz" }); stateful.observe(dfd.callback(function (oldValues) { - assert.deepEqual(oldValues, {foo: "Foo"}); + assert.deepEqual(oldValues, {foo: "Foo", bar: "Bar", zaz: "Zaz"}); })); - stateful.notifyCurrentValue("foo"); + stateful.notifyCurrentValue("foo", "bar"); + stateful.notifyCurrentValue("zaz"); }, "Stateful.PropertyListObserver#deliver(), Stateful.PropertyListObserver#discardChanges()": function () { var changes = [],