can-define-backup
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -5,4 +5,5 @@ var DefineMap = require('can-define/map/map'); | ||
var defineBackup = require('can-define-backup'); | ||
defineBackup(DefineMap); | ||
var MyMap = defineBackup(DefineMap.extend({})); | ||
require('steal-qunit'); | ||
@@ -14,3 +15,3 @@ | ||
setup: function () { | ||
Recipe = DefineMap.extend('Recipe', { | ||
Recipe = MyMap.extend('Recipe', { | ||
name: 'string' | ||
@@ -36,9 +37,9 @@ }); | ||
test('backup / restore with associations', function () { | ||
var Instruction = DefineMap.extend('Instruction', { | ||
var Instruction = MyMap.extend('Instruction', { | ||
description: 'string' | ||
}); | ||
var Cookbook = DefineMap.extend('Cookbook', { | ||
var Cookbook = MyMap.extend('Cookbook', { | ||
title: 'string' | ||
}); | ||
var Recipe = DefineMap.extend('Recipe', { | ||
var Recipe = MyMap.extend('Recipe', { | ||
instructions: { | ||
@@ -91,3 +92,3 @@ Type: Instruction.List | ||
test('backup restore nested observables', function () { | ||
var observe = new DefineMap({ | ||
var observe = new MyMap({ | ||
nested: { | ||
@@ -110,3 +111,3 @@ test: 'property' | ||
test('backup removes properties that were added (#607)', function () { | ||
var map = new DefineMap({ | ||
var map = new MyMap({ | ||
foo: 'string' | ||
@@ -113,0 +114,0 @@ }); |
"use strict"; | ||
//allows you to backup and restore a map instance | ||
var assign = require('can-assign'); | ||
var canReflect = require('can-reflect'); | ||
@@ -21,2 +20,13 @@ var SimpleObservable = require('can-simple-observable'); | ||
var assignNonEnumerable = function(base, props) { | ||
for(var prop in props) { | ||
Object.defineProperty(base, prop, { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: props[prop] | ||
}); | ||
} | ||
}; | ||
var observables = new WeakMap(); | ||
@@ -34,3 +44,3 @@ | ||
function defineBackup(Map) { | ||
assign(Map.prototype, { | ||
assignNonEnumerable(Map.prototype, { | ||
@@ -82,5 +92,6 @@ backup: function () { | ||
}); | ||
return; | ||
return Map; | ||
} | ||
module.exports = exports = defineBackup; |
{ | ||
"name": "can-define-backup", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Backup and restore a DefineMap state", | ||
@@ -5,0 +5,0 @@ "homepage": "https://canjs.com", |
21801
218