emo

ember-model-original-attributes

The default blueprint for ember-cli addons.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

3

Maintenance

Last Commit

4yrs ago

Contributors

1

Package

Dependencies

1

Size (min+gzip)

0.2KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

ember-model-original-attributes

Build Status npm version

Add new computed properties to Models with values equal to some saved attribute's values.

Install

ember install ember-model-original-attributes

Usage

Create a section originalAttributes in the config/environment.js:

module.exports = function(/* environment, appConfig */) {
  return {
    originalAttributes: {
      prefix: 'old',
      models: {
        user: {
          attrs: ['firstName', 'lastName']
        }
      }
    }
  };
};

Model user will have two new computed properties called oldFirstName and oldLastName. Both of them will be equal to the saved values of the firstName and lastName.

Existing computed properties, attributes or relationships won't be overridden.

Prefix original is used by default.

Property models is a hash with keys equal to Model names. Its values are hashes with property attrs. Each attrs is an array with attribute names that should be processed.

store.findRecord('user', '1').then(user => {
  user.get('firstName');      // 'Jim'
  user.get('oldFirstName');   // 'Jim'
  user.set('firstName', 'Tychus');
  user.get('firstName');      // 'Tychus'
  user.get('oldFirstName');   // 'Jim'
  user.save().then(() => {
    user.get('firstName');    // 'Tychus'
    user.get('oldFirstName'); // 'Tychus'
  });
});

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100