Ember-immer-changeset
Minimum Requirements
- Ember.js v4.4 or above
- Ember CLI v4.4 or above
- Node.js v16 or above
Installation
ember install ember-immer-changeset
Documentation
https://triptyk.github.io/ember-immer-changeset/
Example
const userData = {
id: 1,
name: 'John Doe',
email: 'johndoe@example.com',
age: 30,
};
const userChangeset = new ImmerChangeset(userData);
console.log('Initial User Data:', userChangeset.data);
userChangeset.set('name', 'Jane Doe');
userChangeset.set('age', 31);
console.log('Is Dirty:', userChangeset.isDirty);
console.log('Changes:', userChangeset.changes);
await userChangeset.validate((draftData) => {
userChangeset.removeErrors();
console.log('Validating:', draftData);
if (draftData.age < 18) {
userChangeset.addError({
originalValue: draftData.age,
value: 18,
key: 'age',
});
}
});
if (userChangeset.isValid) {
userChangeset.execute();
console.log('Updated User Data:', userChangeset.data);
userChangeset.save();
console.log('Is Dirty:', userChangeset.isDirty);
console.log('User Data after Saving:', userChangeset.data);
}