🎁 New shorthand for clone and commit!
This version brings a new shorthand syntax for the Clone and Commit pattern. You can now pass an object to an instance's clone()
method, and that value will be merged into the clone right away.
The Old Way
Previously, this was the only way to clone and commit.
const todo = Todo.getFromStore(1)
const clone = instance.clone()
Object.assign(clone, { description: 'boilerplate code sucks' })
clone.commit()
todo.save()
It's not the prettiest syntax. It was designed as an elegant (in the eye of the beholder;) way to get around Vuex limitations / best practices.
The New Way
Here is the new syntax, thanks to @mrfrase3's contribution:
const todo = Todo.getFromStore(1)
todo.clone({ description: 'all in one line' }).save()
The above example will update the local instance after the call to save()
returns from the API server. If you want to do eager updating, so the UI updates BEFORE the request is made, just sneak a .commit()
in before save:
const todo = Todo.getFromStore(1)
todo.clone({ description: 'all in one line' }).commit().save()
The original method of clone and commit isn't going away. We just have a shorthand way of accomplishing the same thing, now.