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
2
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 1.0.4 to 2.0.0

.npmignore

42

addon/model.js

@@ -28,16 +28,22 @@ import Ember from "ember";

var attr = function() {
var meta = {isAttribute: true};
var meta = {isAttribute: true, defaults: arguments[0]};
return Ember.computed(function(key, value) {
var data = this.get("_data") || {};
var dirty = this.get("_dirty") || {};
var primed = this.get("_primed") || {};
var defaults = this.get("_defaults") || {};
if (arguments.length === 2) {
if (!this.get("isDirty") && !this.get("isPrimed")) {
var oldState = clone(this);
this.set("_oldState", oldState);
defaults[key] = meta.defaults;
if (!this.get("isDirty")) {
this.set("_oldState", clone(this));
}
var primed = value === "" && data[key] === undefined;
if(!primed) {
this.set("isPrimed", true);
dirty[key + ":isDirty"] = true;
data[key] = value;
var ready = (value === "" || value === undefined) && (data[key] === undefined);
dirty[key + ":isDirty"] = true;
data[key] = value;
if(!ready && !primed[key + ":isPrimed"]) {
primed[key + ":isPrimed"] = true;
}

@@ -54,2 +60,3 @@ }

this._setup();
this.set("_defaults", {});
this.set("_data", clone(this));

@@ -73,2 +80,3 @@ this.set("_oldState", clone(this));

this.set("_dirty", {});
this.set("_primed", {});
},

@@ -79,10 +87,18 @@ _setup: function() {

attributes.forEach(function(attrName) {
var dynamicKey = attrName + "IsDirty";
Ember.defineProperty(self, dynamicKey, Ember.computed(function() {
var dynamicDirtyKey = attrName + "IsDirty";
Ember.defineProperty(self, dynamicDirtyKey, Ember.computed(function() {
var current = this.get(attrName);
var defaults = this.get("_defaults")[attrName];
var original = this.get("_oldState." + attrName);
var dirty = this.get("_dirty");
var dirtyKey = attrName + ":isDirty";
return original === current ? undefined : dirty[dirtyKey];
}).property("_dirty", "" + attrName));
var legit = (current === defaults && original === undefined) || (original === current);
return legit ? undefined : dirty[dirtyKey];
}).property("_dirty", "_defaults", "" + attrName));
var dynamicPrimedKey = attrName + "IsPrimed";
Ember.defineProperty(self, dynamicPrimedKey, Ember.computed(function() {
var primed = this.get("_primed");
var primedKey = attrName + ":isPrimed";
return primed[primedKey];
}).property("_primed", "" + attrName));
});

@@ -89,0 +105,0 @@ var modelIsDirtyAttrs = [];

ember-cli-simple-store Changelog
==============================
2.0.0
-----
* [FEATURE]: attr now supports default value for dirty tracking
([#13](https://github.com/toranb/ember-cli-simple-store/pull/13))
1.0.4

@@ -5,0 +12,0 @@ -----

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

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

@@ -205,2 +205,19 @@ # ember-cli-simple-store

For new forms that start with undefined properties you can define the default state for isDirty. Example: you have a model that is bound to a form with a checkbox input. The create form starts with a new model so each bound property is undefined. If the user decides to check the bound checkbox (setting the value to true) and then decides to uncheck it (setting the value to false) you would expect the form is not dirty - but because undefined !== false you find the model is dirty. To prevent this behavior set a default value for dirty tracking on the models attr like so.
```js
var Animal = Model.extend({
omnivore: attr(false)
});
var animal = Animal.create();
animal.get("omnivore"); //undefined
animal.get("isDirty"); //false
animal.set("omnivore", true);
animal.get("isDirty"); //true
animal.set("omnivore", false);
animal.get("isDirty"); //false
```
## Example applications

@@ -207,0 +224,0 @@

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