can-define-backup
Advanced tools
Comparing version 0.0.1 to 1.0.0-pre.0
@@ -1,3 +0,4 @@ | ||
var compute = require('can-compute'); | ||
var DefineMap = require('can-define/map/map'); | ||
var Observation = require("can-observation"); | ||
var canReflect = require("can-reflect"); | ||
@@ -114,3 +115,3 @@ require('can-define-backup'); | ||
test('isDirty wrapped in a compute should trigger changes #1417', function() { | ||
test('isDirty wrapped in an observation should trigger changes #1417', function() { | ||
expect(2); | ||
@@ -123,10 +124,10 @@ var recipe = new Recipe({ | ||
var c = compute(function() { | ||
var obs = new Observation(function(){ | ||
return recipe.isDirty(); | ||
}); | ||
ok(!c(), 'isDirty is false'); | ||
ok(!obs.get(), 'isDirty is false'); | ||
c.bind('change', function() { | ||
ok(c(), 'isDirty is true and a change has occurred'); | ||
canReflect.onValue(obs, function(){ | ||
ok(obs.get(), 'isDirty is true and a change has occurred'); | ||
}); | ||
@@ -133,0 +134,0 @@ |
//allows you to backup and restore a map instance | ||
var compute = require('can-compute'); | ||
var DefineMap = require('can-define/map/map'); | ||
var compare = require('can-set/src/compare'); | ||
var assign = require("can-util/js/assign/assign"); | ||
var assign = require("can-assign"); | ||
var canReflect = require("can-reflect"); | ||
var SimpleObservable = require('can-simple-observable'); | ||
@@ -19,11 +20,18 @@ var flatProps = function (a, cur) { | ||
var observables = new WeakMap(); | ||
// var oldSetup = DefineMap.prototype.init; | ||
function getBackup(map) { | ||
var obs = observables.get(map); | ||
if(!obs) { | ||
obs = new SimpleObservable(); | ||
observables.set(map, obs); | ||
} | ||
return obs; | ||
} | ||
assign(DefineMap.prototype, { | ||
_backupStore: compute(), | ||
backup: function () { | ||
this._backupStore(this.serialize()); | ||
var store = getBackup(this); | ||
canReflect.setValue(store, this.serialize()); | ||
return this; | ||
@@ -33,3 +41,4 @@ }, | ||
isDirty: function (checkAssociations) { | ||
var backupStore = this._backupStore(); | ||
var store = getBackup(this); | ||
var backupStore = canReflect.getValue(store); | ||
if(!backupStore){ | ||
@@ -47,3 +56,5 @@ return false; | ||
restore: function (restoreAssociations) { | ||
var props = restoreAssociations ? this._backupStore() : flatProps(this._backupStore(), this); | ||
var store = getBackup(this); | ||
var curVal = canReflect.getValue(store); | ||
var props = restoreAssociations ? curVal : flatProps(curVal, this); | ||
if (this.isDirty(restoreAssociations)) { | ||
@@ -50,0 +61,0 @@ for(var prop in props) { |
{ | ||
"name": "can-define-backup", | ||
"version": "0.0.1", | ||
"version": "1.0.0-pre.0", | ||
"description": "Backup and restore a DefineMap state", | ||
@@ -41,38 +41,21 @@ "homepage": "https://canjs.com", | ||
"system": { | ||
"main": "can-define-backup", | ||
"configDependencies": [ | ||
"live-reload" | ||
], | ||
"npmIgnore": [ | ||
"documentjs", | ||
"testee", | ||
"generator-donejs", | ||
"donejs-cli", | ||
"steal-tools" | ||
], | ||
"npmAlgorithm": "flat" | ||
"main": "can-define-backup" | ||
}, | ||
"dependencies": { | ||
"can-compute": "^3.0.0", | ||
"can-connect": "^1.0.0", | ||
"can-define": "^1.0.4", | ||
"can-fixture": "^1.0.0", | ||
"can-jquery": "^3.0.1", | ||
"can-list": "^3.0.0", | ||
"can-set": "^1.0.0", | ||
"can-util": "^3.0.1" | ||
"can-assign": "^1.1.1", | ||
"can-define": "^2.0.0-pre.0", | ||
"can-reflect": "^1.11.0", | ||
"can-set": "^1.3.3", | ||
"can-simple-observable": "^2.0.0-pre.25" | ||
}, | ||
"devDependencies": { | ||
"can-define-define": "^3.0.0-pre.2", | ||
"can-ssr": "^0.11.6", | ||
"can-observation": "^4.0.0-pre.0", | ||
"cssify": "^0.6.0", | ||
"documentjs": "^0.4.2", | ||
"donejs-cli": "^0.7.0", | ||
"generator-donejs": "^0.7.0", | ||
"jshint": "^2.9.1", | ||
"steal": "^0.14.0", | ||
"steal-qunit": "^0.1.1", | ||
"steal-tools": "^0.14.0", | ||
"steal": "^1.0.0", | ||
"steal-qunit": "^1.0.0", | ||
"steal-tools": "^1.0.0", | ||
"testee": "^0.2.4" | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21606
5
8
203
1
+ Addedcan-assign@^1.1.1
+ Addedcan-reflect@^1.11.0
+ Addedcan-data-types@1.2.1(transitive)
+ Addedcan-define@2.8.1(transitive)
+ Addedcan-diff@1.5.1(transitive)
+ Addedcan-event-queue@1.1.8(transitive)
+ Addedcan-key@1.2.1(transitive)
+ Addedcan-observation@4.2.0(transitive)
+ Addedcan-observation-recorder@1.3.1(transitive)
+ Addedcan-queues@1.3.2(transitive)
+ Addedcan-reflect-dependencies@1.1.2(transitive)
+ Addedcan-simple-observable@2.5.0(transitive)
+ Addedcan-single-reference@1.3.0(transitive)
+ Addedcan-string-to-any@1.2.1(transitive)
- Removedcan-compute@^3.0.0
- Removedcan-connect@^1.0.0
- Removedcan-fixture@^1.0.0
- Removedcan-jquery@^3.0.1
- Removedcan-list@^3.0.0
- Removedcan-util@^3.0.1
- Removedcan-attribute-encoder@0.3.5(transitive)
- Removedcan-compute@3.3.10(transitive)
- Removedcan-connect@1.5.18(transitive)
- Removedcan-define@1.5.9(transitive)
- Removedcan-event@3.7.7(transitive)
- Removedcan-fixture@1.2.2(transitive)
- Removedcan-global@1.0.1(transitive)
- Removedcan-jquery@3.2.5(transitive)
- Removedcan-list@3.2.2(transitive)
- Removedcan-make-rest@0.1.4(transitive)
- Removedcan-map@3.6.1(transitive)
- Removedcan-observation@3.3.6(transitive)
- Removedcan-reflect-promise@1.1.5(transitive)
- Removedcan-route@3.3.4(transitive)
- Removedcan-simple-map@3.3.2(transitive)
- Removedcan-simple-observable@1.0.2(transitive)
- Removedcan-stache@3.15.1(transitive)
- Removedcan-stache-bindings@3.11.12(transitive)
- Removedcan-stache-key@0.1.4(transitive)
- Removedcan-test-helpers@1.1.4(transitive)
- Removedcan-validate-interface@0.1.2(transitive)
- Removedcan-view-callbacks@3.2.5(transitive)
- Removedcan-view-import@3.2.9(transitive)
- Removedcan-view-live@3.2.6(transitive)
- Removedcan-view-model@3.5.2(transitive)
- Removedcan-view-nodelist@3.1.1(transitive)
- Removedcan-view-parser@3.8.3(transitive)
- Removedcan-view-scope@3.6.0(transitive)
- Removedcan-view-target@3.1.6(transitive)
- Removedjquery@3.7.1(transitive)
- Removedsteal-stache@3.1.3(transitive)
Updatedcan-define@^2.0.0-pre.0
Updatedcan-set@^1.3.3