Skip to content

Commit

Permalink
fix initialize without new
Browse files Browse the repository at this point in the history
  • Loading branch information
lieuwex committed Jul 2, 2015
1 parent 847671e commit 78cce1d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'simply:strict-reactive-var',
version: '1.0.3',
version: '1.0.4',
summary: 'Thin strictly type checking wrapper around reactive-var.',
git: 'https://github.com/simplyGits/strict-reactive-var',
documentation: 'README.md',
Expand Down
25 changes: 8 additions & 17 deletions strict-reactive-var-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Tinytest.add('be able to initialized with and without `new`', function (test) {
test.instanceOf(new SReactiveVar(null), SReactiveVar);
test.instanceOf(SReactiveVar(null), SReactiveVar);
var a = new SReactiveVar(null)
var b = SReactiveVar(null)

test.instanceOf(a, SReactiveVar)
test.instanceOf(b, SReactiveVar)

test.equal(a.get(), b.get())
test.equal(a._pattern, b._pattern)
})

Tinytest.add('set and retrieve values', function (test) {
Expand All @@ -10,21 +16,6 @@ Tinytest.add('set and retrieve values', function (test) {
test.equal(val.get(), 420)
})

Tinytest.add('set values and be reactive', function (test) {
var val = new SReactiveVar(Number, 0)

Tracker.autorun(Meteor.bindEnvironment(function (c) {
var value = val.get()
if (c.firstRun) {
test.equal(value, 0)
} else {
test.equal(value, 1)
}
}))

val.set(1)
})

Tinytest.add('check types', function (test) {
var val = new SReactiveVar(Number, 0)
test.equal(val.get(), 0)
Expand Down
6 changes: 5 additions & 1 deletion strict-reactive-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ SReactiveVar = function (pattern /*, args */) {
var args = [].slice.call(arguments, 1)

if (!(this instanceof SReactiveVar)) {
return new SReactiveVar(arguments)
var x = function (args) {
return SReactiveVar.apply(this, args)
}
x.prototype = SReactiveVar.prototype
return new x(arguments)
}
if (pattern === undefined) {
throw new ReferenceError('`pattern` is required')
Expand Down

0 comments on commit 78cce1d

Please sign in to comment.