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-2296master
parent
38b4a58dde
commit
4d981bd39f
|
@ -72,7 +72,8 @@ module.exports = Trait( 'Cascading' )
|
||||||
* @param {string} key store key
|
* @param {string} key store key
|
||||||
* @param {Store} value Store to attach
|
* @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 )
|
'virtual abstract override public add': function( key, value )
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,23 +75,17 @@ module.exports = Class( 'MemoryStore' )
|
||||||
/**
|
/**
|
||||||
* Add item to store under `key` with value `value`
|
* 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 {string} key store key
|
||||||
* @param {*} value value for 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 )
|
'virtual public add': function( key, value )
|
||||||
{
|
{
|
||||||
this._store[ key ] = value;
|
this._store[ key ] = value;
|
||||||
|
|
||||||
return Promise.resolve( {
|
return Promise.resolve( this.__inst );
|
||||||
key: key,
|
|
||||||
value: value,
|
|
||||||
} );
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@ module.exports = Interface( 'Store',
|
||||||
* @param {string} key store key
|
* @param {string} key store key
|
||||||
* @param {*} value value for 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' ],
|
'public add': [ 'key', 'value' ],
|
||||||
|
|
||||||
|
|
|
@ -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 sut = Sut();
|
||||||
const value = 'val';
|
|
||||||
|
|
||||||
return expect(
|
return expect(
|
||||||
Sut().add( key, value )
|
sut.add( 'foo', 'bar' )
|
||||||
).to.eventually.deep.equal( { key: key, value: value } );
|
).to.eventually.equal( sut );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue