From 4d981bd39f37837b23d79b92829360656c148859 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 26 Jan 2017 16:35:29 -0500 Subject: [PATCH] Store#add to return self This allows for Promise chaining (and consequently temporary classes, great for testing). * src/store/MemoryStore.js (add): Resolve promise to self. Modify docblock. * src/store/Store.js (add): Modify docblock. * src/store/Cascading.js (add): Modify docblock. * test/store/MemoryStoreTest.js: Modify test accordingly. DEV-2296 --- src/store/Cascading.js | 3 ++- src/store/MemoryStore.js | 12 +++--------- src/store/Store.js | 3 ++- test/store/MemoryStoreTest.js | 9 ++++----- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/store/Cascading.js b/src/store/Cascading.js index 5e6c55d..70155a7 100644 --- a/src/store/Cascading.js +++ b/src/store/Cascading.js @@ -72,7 +72,8 @@ module.exports = Trait( 'Cascading' ) * @param {string} key store key * @param {Store} value Store to attach * - * @return {Promise} promise to add item to store + * @return {Promise.} promise to add item to store, resolving to + * self (for chaining) */ 'virtual abstract override public add': function( key, value ) { diff --git a/src/store/MemoryStore.js b/src/store/MemoryStore.js index d4b92da..a055b9f 100644 --- a/src/store/MemoryStore.js +++ b/src/store/MemoryStore.js @@ -75,23 +75,17 @@ module.exports = Class( 'MemoryStore' ) /** * Add item to store under `key` with value `value` * - * The promise will be fulfilled with an object containing the - * `key` and `value` added to the store; this is convenient for - * promises. - * * @param {string} key store key * @param {*} value value for key * - * @return {Promise} promise to add item to store + * @return {Promise.} promise to add item to store, resolving to + * self (for chaining) */ 'virtual public add': function( key, value ) { this._store[ key ] = value; - return Promise.resolve( { - key: key, - value: value, - } ); + return Promise.resolve( this.__inst ); }, diff --git a/src/store/Store.js b/src/store/Store.js index 3daf69b..acd96c4 100644 --- a/src/store/Store.js +++ b/src/store/Store.js @@ -44,7 +44,8 @@ module.exports = Interface( 'Store', * @param {string} key store key * @param {*} value value for key * - * @return {Promise} promise to add item to store + * @return {Promise.} promise to add item to store, resolving to + * self (for chaining) */ 'public add': [ 'key', 'value' ], diff --git a/test/store/MemoryStoreTest.js b/test/store/MemoryStoreTest.js index 7d47bc2..452dbbb 100644 --- a/test/store/MemoryStoreTest.js +++ b/test/store/MemoryStoreTest.js @@ -60,14 +60,13 @@ describe( 'store.MemoryStore', () => } ); - it( 'provides the key and value of the added item', () => + it( 'returns self with promise', () => { - const key = 'key'; - const value = 'val'; + const sut = Sut(); return expect( - Sut().add( key, value ) - ).to.eventually.deep.equal( { key: key, value: value } ); + sut.add( 'foo', 'bar' ) + ).to.eventually.equal( sut ); } ); } );