Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitzm@lovullo.com>2017-01-26 16:35:29 -0500
committerMike Gerwitz <gerwitzm@lovullo.com>2017-01-29 22:44:34 -0500
commit4d981bd39f37837b23d79b92829360656c148859 (patch)
treee1e2cac42eb41c6f7b67205c71a8abc538417586
parent38b4a58ddea6a4439034e1a06ef63c3a4d5ebe42 (diff)
downloadliza-4d981bd39f37837b23d79b92829360656c148859.tar.gz
liza-4d981bd39f37837b23d79b92829360656c148859.tar.bz2
liza-4d981bd39f37837b23d79b92829360656c148859.zip
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
-rw-r--r--src/store/Cascading.js3
-rw-r--r--src/store/MemoryStore.js12
-rw-r--r--src/store/Store.js3
-rw-r--r--test/store/MemoryStoreTest.js9
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.<Store>} 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.<Store>} 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.<Store>} 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 );
} );
} );