ember-object-update
Update Ember objects with ease
Installation
ember install ember-object-update
Ever get tired of dealing with Ember.get
and Ember.set
when you're trying to update properties on an object, or component?
Does this look familiar?
Ember
Or this?
actions: { let oldValue = Ember; let newValue = oldValue Ember }
If you find yourself wishing there was an easier way to make these kinds of updates, then ember-object-update
is for you!
ember-object-update
is a simple add-on that (currently) provides a single utility function: update
. The update
function lets you use a function to compute a new value for a property and update the property all with one function.
update
accepts three arguments:
- obj: The object you want to update
- path: A string that contains the path to the value you want to update, e.g.
names.nickname
- updateFn: A function whose first argument is the current value of the property you're updating, and whose result is the new value you'd like to set.
Examples
This'll probably be easier if you see it in action, so check out the examples below:
Doubling all the values in an array property
; let obj = EmberObject;}); // The old wayEmber; // [2, 4, 6] // Using the `update` method;
Also, it works in components!
Updating component properties from an action
; Component;
Crazy nested things (plus array indexes!)
; let crazyNestedPOJO = a: b: c: "some deeply nested value" ; ;
Closing over local variables in your updater function
; actions: { // close over the `multiplier` value when pass our updater function into `update` ; }
Running the dummy app
ember serve
- Visit your app at http://localhost:4200.
Running Tests
npm test
(Runsember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
Building
ember build
For more information on using ember-cli, visit http://ember-cli.com/.