Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-cli-simple-store

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-simple-store - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

23

addon/model.js

@@ -17,3 +17,4 @@ import Ember from "ember";

return function(key, value) {
var data = this.get("$data") || {};
var data = this.get("_data") || {};
var dirty = this.get("_dirty") || {};
if (arguments.length === 2) {

@@ -25,6 +26,7 @@ if (!this.get("isDirty")) {

this.set("isDirty", true);
dirty["%@:isDirty".fmt(key)] = true;
data[key] = value;
}
return data[key];
}.property('$data').meta(meta);
}.property("_data").meta(meta);
};

@@ -34,4 +36,4 @@

init: function() {
this.set('$data', {});
this.set("isDirty", false);
this.set("_data", {});
this._reset();
},

@@ -43,3 +45,3 @@ rollback: function() {

}
this.set("isDirty", false);
this._reset();
},

@@ -49,3 +51,14 @@ save: function() {

this.set("_oldState", oldState);
this._reset();
},
_reset: function() {
this.set("isDirty", false);
this.set("_dirty", {});
},
unknownProperty: function(key) {
if (key === "_dirty") { return; }
var dirty = this.get("_dirty");
if (key.indexOf(":isDirty") > 0) {
return dirty[key];
}
}

@@ -52,0 +65,0 @@ });

{
"name": "ember-cli-simple-store",
"version": "0.2.1",
"version": "0.3.0",
"description": "ember-cli addon that provides a simple identity map for ember.js web applications",

@@ -5,0 +5,0 @@ "directories": {

@@ -172,11 +172,19 @@ # ember-cli-simple-store

//save your object to reset isDirty
var person = Person.create({id: 1, firstName: 'x', lastName: 'y'});
person.set('firstName', 'toran');
var person = Person.create({id: 1, firstName: "x", lastName: "y"});
person.set("firstName", "toran");
person.save();
//rollback your object to reset isDirty and restore it
person.set('firstName', 'foobar');
person.set("firstName", "foobar");
person.rollback();
```
If you want to know if an individual property isDirty you can ask like so
```js
person.get("firstName:isDirty"); //undefined
person.set("firstName", "foobar");
person.get("firstName:isDirty"); //true
```
## Running the unit tests

@@ -183,0 +191,0 @@

@@ -145,1 +145,45 @@ import Ember from "ember";

});
test("isDirty on the individual property will update if attr is changed", function(){
brandon = Person.create(data);
equal("Brandon", brandon.get("firstName"));
equal("Williams", brandon.get("lastName"));
equal(undefined, brandon.get("firstName:isDirty"));
equal(undefined, brandon.get("lastName:isDirty"));
brandon.set("lastName", "wat");
equal(undefined, brandon.get("firstName:isDirty"));
equal(true, brandon.get("lastName:isDirty"));
});
test("isDirty on the individual property is reset after save", function(){
brandon = Person.create(data);
equal("Brandon", brandon.get("firstName"));
equal(undefined, brandon.get("firstName:isDirty"));
brandon.set("firstName", "baz");
equal(true, brandon.get("firstName:isDirty"));
brandon.save();
equal(undefined, brandon.get("firstName:isDirty"));
});
test("isDirty on the individual property is reset after rollback", function(){
brandon = Person.create(data);
equal("Brandon", brandon.get("firstName"));
equal(undefined, brandon.get("firstName:isDirty"));
brandon.set("firstName", "baz");
equal(true, brandon.get("firstName:isDirty"));
brandon.rollback();
equal(undefined, brandon.get("firstName:isDirty"));
});
test("rollback after it has been saved will be a no-op at the property level also", function(){
brandon = Person.create(data);
equal(undefined, brandon.get("firstName:isDirty"));
brandon.set("firstName", "baz");
equal(true, brandon.get("firstName:isDirty"));
brandon.save();
equal(undefined, brandon.get("firstName:isDirty"));
equal("baz", brandon.get("firstName"));
brandon.rollback();
equal(undefined, brandon.get("firstName:isDirty"));
equal("baz", brandon.get("firstName"));
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc