# ember-unchanged-attributes

> Allows to get unchanged value of attributes of model object after they were changed.

Latest version **0.0.2** (published 2017-11-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-unchanged-attributes
pnpm add ember-unchanged-attributes
yarn add ember-unchanged-attributes
bun add ember-unchanged-attributes
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2017-11-07 |
| First published | 2017-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.12.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Pavel Astraukh |
| Maintainers | enotpoloskun |
| Keywords | ember-addon, unchanged attributes |

## Links

- npm: https://www.npmjs.com/package/ember-unchanged-attributes
- Repository: https://github.com/EnotPoloskun/ember-unchanged-attributes
- Homepage: https://github.com/EnotPoloskun/ember-unchanged-attributes#readme
- Issues: https://github.com/EnotPoloskun/ember-unchanged-attributes/issues
- npm.io page: https://npm.io/package/ember-unchanged-attributes

## Dependencies (1)

- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^5.1.7

## Recent versions

- 0.0.2 (latest) — 2017-11-07
- 0.0.1 — 2017-09-03

## README

# ember-unchanged-attributes

[![Build Status](https://travis-ci.org/EnotPoloskun/ember-unchanged-attributes.svg?branch=master)](https://travis-ci.org/EnotPoloskun/ember-unchanged-attributes)

Ember plugin which allows you to get initial value of model object's attributes after they were changed.

Sometimes, you don't need to update attributes values in view until model is saved. For example, you can have edit form in modal and you don't want values to update on background until model object is successfully saved, because it can confuse user.
This plugin can help you with this issue!

## Installation

`ember install ember-unchanged-attributes`

## Usage

First, you need to import module and extend needed model.

```js
import UnchangedAttributesMixin from 'ember-unchanged-attributes';

DS.Model.extend(UnchangedAttributesMixin, {
  name: attr(),
});
```
After this, you can access unchanged value of any attribute by `unchanged#{AttrName}` property

```js
let user = this.store.createRecord('user', { name: 'Jack' });
user.get('unchangedName');
> "Jack"
user.set('name', 'Billy');
user.get('unchangedName');
> "Jack"
```

After you save object, it will reset unchanged attributes

```js
user.save().then((user) => {
  user.get('unchangedName') // => will equal to "Billy"
});
```

Also, if you wan't to have unchanged properties for specific attributes only, you can specify ```_unchangedAttributesList``` in your model. And you can also specify prefix for these attributes with ```_unchangedPrefix```.

```js
import UnchangedAttributesMixin from 'ember-unchanged-attributes';

DS.Model.extend(UnchangedAttributesMixin, {
  _unchangedPrefix: 'original',
  _unchangedAttributesList: ['content'],

  title: attr(),
  content: attr(),
});

...

let article = this.store.createRecord('article', { title: 'Best Article', content: 'Best Content' })
article.set('content', 'Lorem Ipsum')
article.get('originalContent')
> "Best Content"
article.get('originalTitle')
> Will throw exception, since 'title' is not specified in '_unchangedAttributesList'
```

---
_Source: https://npm.io/package/ember-unchanged-attributes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
