ember-deep-set
ember-deep-set
is a simple utility function to deeply set a value on an Ember Object or POJO. Note that this mutates the object.
To install:
ember install ember-deep-set
Why this addon exists
Ember.set
will throw an error if you try to set a value on a non-existent object. For example:
Ember.set({}, 'foo.bar.baz', 123);
With ember-deep-set
, you can safely and deeply set values on POJOs as well as Ember.Objects without having to first create the empty intermediate objects.
Usage
import Ember from 'ember';
import deepSet from 'ember-deep-set';
const { get } = Ember;
let company = {};
deepSet(company, 'region.department.director.name', 'Jim Bob');
deepSet(company, 'region.department.name', 'Accounting');
deepSet(company, 'region.name', 'North America');
get(company, 'region.department.name');
get(company, 'region.department.director');
API
deepSet
is designed to be a drop-in replacement to Ember.set
:
deepSet( object, key, value )
Parameters:
object
: {Ember.Object|Object}
The object to set values onkey
: {String}
The key to setvalue
: {Any}
Value to set
Returns:
value
: {Any}
Value that was passed in
Installation
git clone <repository-url>
this repositorycd ember-deep-set
npm install
bower install
Running
Running Tests
npm test
(Runs ember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
Building
For more information on using ember-cli, visit https://ember-cli.com/.