Skip to content

Commit

Permalink
Merge pull request #17 from canjs/enum
Browse files Browse the repository at this point in the history
Make added methods non-enumerable
  • Loading branch information
matthewp authored Sep 11, 2018
2 parents f170bd4 + c6047bb commit c2e089a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
17 changes: 14 additions & 3 deletions can-define-backup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";
//allows you to backup and restore a map instance
var assign = require('can-assign');
var canReflect = require('can-reflect');
var SimpleObservable = require('can-simple-observable');
var diffDeep = require("can-diff/deep/deep");
Expand All @@ -18,6 +17,17 @@ var flatProps = function (a, cur) {
return obj;
};

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();

function getBackup(map) {
Expand All @@ -30,7 +40,7 @@ function getBackup(map) {
}

function defineBackup(Map) {
assign(Map.prototype, {
assignNonEnumerable(Map.prototype, {

backup: function () {
var store = getBackup(this);
Expand Down Expand Up @@ -77,7 +87,8 @@ function defineBackup(Map) {
return this;
}
});
return;

return Map;
}

module.exports = exports = defineBackup;
15 changes: 8 additions & 7 deletions can-define-backup_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ var DefineMap = require('can-define/map/map');
var Observation = require('can-observation');
var canReflect = require('can-reflect');
var defineBackup = require('can-define-backup');
defineBackup(DefineMap);

var MyMap = defineBackup(DefineMap.extend({}));

require('steal-qunit');

var Recipe;

QUnit.module('can/define/backup', {
setup: function () {
Recipe = DefineMap.extend('Recipe', {
Recipe = MyMap.extend('Recipe', {
name: 'string'
});
}
Expand All @@ -31,13 +32,13 @@ test('backing up', function () {
});

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: {
Type: Instruction.List
},
Expand Down Expand Up @@ -85,7 +86,7 @@ test('backup / restore with associations', function () {
});

test('backup restore nested observables', function () {
var observe = new DefineMap({
var observe = new MyMap({
nested: {
test: 'property'
}
Expand All @@ -103,7 +104,7 @@ test('backup restore nested observables', function () {
});

test('backup removes properties that were added (#607)', function () {
var map = new DefineMap({
var map = new MyMap({
foo: 'string'
});
map.backup();
Expand Down

0 comments on commit c2e089a

Please sign in to comment.