Getting Started
Package Managers
npm: npm install mini-store.js
bower: bower install mini-store.js
MiniStore
Lightweight class to store and manage data.
Parameters
Name | Type | Description |
---|---|---|
defaults | object,array | Base properties to set on object at instantiation. |
var store = new MiniStore({
nested: { key: 'value' }
});
set
Add properties to on attributes object. Will overwrite if value currently exists for key. Works as a deep merge.
Parameters
Name | Type | Description |
---|---|---|
properties | object | Will set each key as a property to store. |
key | key | Name of key to set in store. |
value | * | Used when key name passed. Sets value of key in store. |
options | object |
options
Name | Type | Description |
---|---|---|
flat | boolean | If merge should be flat rather than deep (deep by default). |
silent | boolean | If we should silence the change event that fires if a property is altered. |
Returns
Type | Description |
---|---|
object | - store instance. |
store.set({
'nested:key': { key: 'newvalue' }
}, true);
store.set('nested:key', 'value');
'nested:'key': { key: 'newvalue' }
});
unset
Remove values from attributes object. If the key passed represents an object in the attributes object, all data within the object will be removed.
Parameters
Name | Type | Description |
---|---|---|
key | string | Namespaced key to delete value of. |
Returns
Type | Description |
---|---|
object | - store instance. |
store.unset('nested');
get
Get value from store.
Parameters
Name | Type | Description |
---|---|---|
name | string | String representation of key to return from store. If no key is passed, the entire attributes object will be returned. |
Returns
Type | Description |
---|---|
* | - queried value. |
var val = store.get('key');
triggerMethod
Trigger an event and/or a corresponding method name. If method exists it will be invoked first.
Parameters
Name | Type | Description |
---|---|---|
eventName | string | Name of event to trigger. |
api.triggerMethod('some:event');
// will attempt to call onSomeEvent
triggerMethodName
Returns the name of the method to be triggered in `triggerMethod`
Parameters
Name | Type | Description |
---|---|---|
eventName | string | Name of event to transform. |
Returns
Type | Description |
---|---|
string | Name of method to call. |
api.triggerMethodName('some:event');
// returns onSomeEvent
Test
All dependencies must be installed (npm install
)
Run: npm test
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Also, please don't edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "lib" subdirectory!
License
The MIT License (MIT) Copyright (c) Jarid Margolin <jaridmargolin@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.