Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
do not allow re-use of binding
Browse files Browse the repository at this point in the history
  • Loading branch information
0x8890 committed Jul 9, 2016
1 parent 58a2c1a commit cabc1b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


### 1.1.2 (2016-07-09)
- Fix: disallow re-use of bindings, it doesn't work anyways.


### 1.1.1 (2016-07-05)
- Fix: error messaging in feature detection.

Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function simulacra (obj, def) {
if (!isArray(def))
throw new TypeError('Second argument must be an array.')

if (isProcessedKey in def)
throw new Error('Can not re-use binding.')

if (typeof def[0] === 'string') {
query = def[0]
def[0] = document.querySelector(query)
Expand Down Expand Up @@ -188,6 +191,7 @@ function featureCheck (globalScope) {
// ECMAScript features.
[ Object, 'defineProperty' ],
[ Object, 'freeze' ],
[ Object, 'isFrozen' ],
[ WeakMap ],

// DOM features.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "simulacra",
"description": "One-way data binding for web applications.",
"version": "1.1.1",
"version": "1.1.2",
"license": "MIT",
"author": {
"email": "0x8890@airmail.cc",
Expand Down Expand Up @@ -33,11 +33,11 @@
"browserify-istanbul": "^2.0.0",
"cssnano": "^3.7.1",
"domino": "^1.0.25",
"eslint": "^3.0.0",
"eslint": "^3.0.1",
"eslint-config-boss": "^1.0.4",
"fs-extra": "^0.30.0",
"highlight.js": "^9.5.0",
"html-minifier": "^2.1.7",
"html-minifier": "^3.0.1",
"istanbul": "^0.4.4",
"marked": "^0.3.5",
"mkdirp": "^0.5.1",
Expand Down
16 changes: 10 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var tapdance = require('tapdance')
var comment = tapdance.comment
var ok = tapdance.ok
var pass = tapdance.pass
var fail = tapdance.fail
var run = tapdance.run

var simulacra = require('../lib')
Expand Down Expand Up @@ -129,12 +131,14 @@ run(function () {
ok(outlet.querySelector('.size').textContent === 'XXL',
'continues to work after error')

comment('test rebinding')
outlet.innerHTML = ''
outlet.appendChild(simulacra({
name: 'babby'
}, bindings))
ok(outlet.textContent === 'babby!', 'rebinding works')
comment('rebinding should fail')
try {
simulacra({}, bindings)
fail('should have failed')
}
catch (error) {
pass('rebinding does not work')
}
})


Expand Down

0 comments on commit cabc1b4

Please sign in to comment.