Stop exposing config as a reference. resolves #35

This commit is contained in:
Keegan
2016-03-11 02:25:59 +11:00
parent 3b7c4cda7c
commit b1a6f184ba
5 changed files with 16 additions and 3 deletions
+1 -1
View File
@@ -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). |
+3 -1
View File
@@ -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/'));
});
+2 -1
View File
@@ -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 = {
+1
View File
@@ -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",
+9
View File
@@ -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([]);