1
0
Fork 0

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
master
Mike Gerwitz 2017-01-26 16:35:29 -05:00
parent 38b4a58dde
commit 4d981bd39f
4 changed files with 11 additions and 16 deletions

View File

@ -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 )
{

View File

@ -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 );
},

View File

@ -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' ],

View File

@ -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 );
} );
} );