From b1a6f184ba6a3d90c46e41d314884f5c5810d8d2 Mon Sep 17 00:00:00 2001 From: Keegan Date: Fri, 11 Mar 2016 02:25:59 +1100 Subject: [PATCH] Stop exposing config as a reference. resolves #35 --- README.md | 2 +- gulpfile.js | 4 +++- index.js | 3 ++- package.json | 1 + test/spec/index.js | 9 +++++++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e77a613..1283f44 100755 --- a/README.md +++ b/README.md @@ -613,7 +613,7 @@ Pebble.addEventListener('webviewclosed', function(e) { | Property | Type | Description | |----------|------|-------------| -| `.config` | Array | Reference to the config passed to the constructor and used for generating the page. **WARNING** this is a direct reference, not a copy of the config so any modification you make to it, will be reflected on the original as well | +| `.config` | Array | Copy of the config passed to the constructor and used for generating the page. | | `.customFn` | Function | Reference to the custom function passed to the constructor. **WARNING** this is a direct reference, not a copy of the custom function so any modification you make to it, will be reflected on the original as well | | `.meta` | Object | Contains information about the current user and watch. **WARNING** This will only be populated in the `showConfiguration` event handler. (See example above) | | `.meta.activeWatchInfo` | watchinfo\|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getActiveWatchInfo). | diff --git a/gulpfile.js b/gulpfile.js index e2e891a..3bd50d7 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -94,7 +94,9 @@ gulp.task('clay', ['inlineHtml'], function() { .bundle() .pipe(source('clay.js')) .pipe(buffer()) - .pipe(uglify()) + .pipe(uglify({ + preserveComments: 'license' + })) .pipe(insert.prepend(versionMessage)) .pipe(gulp.dest('./dist/')); }); diff --git a/index.js b/index.js index a77ec45..e7402ff 100755 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ var configPageHtml = require('./tmp/config-page.html'); var toSource = require('tosource'); var standardComponents = require('./src/scripts/components'); var utils = require('./src/scripts/lib/utils'); +var deepcopy = require('deepcopy/build/deepcopy.min'); /** * @param {Array} config - the Clay config @@ -27,7 +28,7 @@ function Clay(config, customFn, options) { options = options || {}; - self.config = config; + self.config = deepcopy(config); self.customFn = customFn || function() {}; self.components = {}; self.meta = { diff --git a/package.json b/package.json index ae8f2b8..831d2cc 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "browserify-istanbul": "^0.2.1", "chai": "^3.4.1", "deamdify": "^0.2.0", + "deepcopy": "^0.6.1", "del": "^2.0.2", "eslint": "^1.5.1", "eslint-config-pebble": "^1.2.0", diff --git a/test/spec/index.js b/test/spec/index.js index 099e378..7dcf8dd 100644 --- a/test/spec/index.js +++ b/test/spec/index.js @@ -135,6 +135,15 @@ describe('Clay', function() { }); }); + describe('.config', function() { + it('is a copy not a reference', function() { + var config = fixture.config(['input', 'text', 'color']); + var clay = fixture.clay(config); + assert.notStrictEqual(clay.config, config); + assert.deepEqual(clay.config, config); + }); + }); + describe('.registerComponent()', function() { it('adds the component to the this.components', function() { var clay = fixture.clay([]);