Skip to content

Commit 0115e2f

Browse files
authored
Asserts! (#23)
* Release 1.3.1
1 parent c43252d commit 0115e2f

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

configs/rollup.esm.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import uglify from 'rollup-plugin-uglify'
2-
1+
const uglify = require('rollup-plugin-uglify')
32
const babel = require('rollup-plugin-babel')
43
const filesize = require('rollup-plugin-filesize')
54

configs/rollup.umd.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import uglify from 'rollup-plugin-uglify'
2-
1+
const uglify = require('rollup-plugin-uglify')
32
const commonjs = require('rollup-plugin-commonjs')
43
const resolve = require('rollup-plugin-node-resolve')
54
const babel = require('rollup-plugin-babel')

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tram-one",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "🚋 Batteries Included View Framework",
55
"main": "dist/tram-one.esm.js",
66
"browser": "dist/tram-one.umd.js",

tram-one.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const xtend = require('xtend')
2+
const assert = require('assert')
23
const nanorouter = require('nanorouter')
34
const belCreateElement = require('bel').createElement
45
const rbelRegister = require('rbel')
@@ -8,6 +9,10 @@ const urlListener = require('url-listener')
89

910
class Tram {
1011
constructor(options) {
12+
if (options) {
13+
assert.equal(typeof options, 'object', 'Tram-One: options should be an object')
14+
}
15+
1116
options = options || {}
1217
const defaultRoute = options.defaultRoute || '/404'
1318

@@ -18,13 +23,18 @@ class Tram {
1823
}
1924

2025
addReducer(key, reducer, state) {
26+
assert.equal(typeof reducer, 'function', 'Tram-One: reducer should be a function')
27+
2128
this.reducers[key] = reducer
2229
this.state[key] = state
2330

2431
return this
2532
}
2633

2734
addRoute(path, page) {
35+
assert.equal(typeof path, 'string', 'Tram-One: path should be a string')
36+
assert.equal(typeof page, 'function', 'Tram-One: page should be a function')
37+
2838
this.router.on(path, (pathParams) => (state) => {
2939
const completeState = xtend(
3040
state, {dispatch: this.store.dispatch},
@@ -37,6 +47,8 @@ class Tram {
3747
}
3848

3949
dispatch(action) {
50+
assert.equal(typeof action, 'object', 'Tram-One: action should be an object')
51+
4052
this.store.dispatch(action)
4153
}
4254

@@ -59,6 +71,9 @@ class Tram {
5971

6072
mount(selector, pathName, state) {
6173
const target = (typeof selector) === 'string' ? document.querySelector(selector) : selector
74+
if (target === null) {
75+
console.warn('Tram-One: could not find target, is the element on the page yet?')
76+
}
6277
if (!target.firstElementChild) {
6378
const targetChild = document.createElement('div')
6479
target.appendChild(targetChild)
@@ -85,6 +100,11 @@ class Tram {
85100
}
86101

87102
static html(registry) {
103+
if (registry) {
104+
assert.equal(typeof registry, 'object', 'Tram-One: registry should be an object')
105+
assert.ok(!(registry instanceof Array), 'Tram-One: registry should be an object')
106+
}
107+
88108
return rbelRegister(belCreateElement, registry || {})
89109
}
90110
}

0 commit comments

Comments
 (0)