Skip to content

Commit

Permalink
Asserts! (#23)
Browse files Browse the repository at this point in the history
* Release 1.3.1
  • Loading branch information
JRJurman authored Jul 22, 2017
1 parent c43252d commit 0115e2f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 1 addition & 2 deletions configs/rollup.esm.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import uglify from 'rollup-plugin-uglify'

const uglify = require('rollup-plugin-uglify')
const babel = require('rollup-plugin-babel')
const filesize = require('rollup-plugin-filesize')

Expand Down
3 changes: 1 addition & 2 deletions configs/rollup.umd.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import uglify from 'rollup-plugin-uglify'

const uglify = require('rollup-plugin-uglify')
const commonjs = require('rollup-plugin-commonjs')
const resolve = require('rollup-plugin-node-resolve')
const babel = require('rollup-plugin-babel')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tram-one",
"version": "1.3.0",
"version": "1.3.1",
"description": "🚋 Batteries Included View Framework",
"main": "dist/tram-one.esm.js",
"browser": "dist/tram-one.umd.js",
Expand Down
20 changes: 20 additions & 0 deletions tram-one.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const xtend = require('xtend')
const assert = require('assert')
const nanorouter = require('nanorouter')
const belCreateElement = require('bel').createElement
const rbelRegister = require('rbel')
Expand All @@ -8,6 +9,10 @@ const urlListener = require('url-listener')

class Tram {
constructor(options) {
if (options) {
assert.equal(typeof options, 'object', 'Tram-One: options should be an object')
}

options = options || {}
const defaultRoute = options.defaultRoute || '/404'

Expand All @@ -18,13 +23,18 @@ class Tram {
}

addReducer(key, reducer, state) {
assert.equal(typeof reducer, 'function', 'Tram-One: reducer should be a function')

this.reducers[key] = reducer
this.state[key] = state

return this
}

addRoute(path, page) {
assert.equal(typeof path, 'string', 'Tram-One: path should be a string')
assert.equal(typeof page, 'function', 'Tram-One: page should be a function')

this.router.on(path, (pathParams) => (state) => {
const completeState = xtend(
state, {dispatch: this.store.dispatch},
Expand All @@ -37,6 +47,8 @@ class Tram {
}

dispatch(action) {
assert.equal(typeof action, 'object', 'Tram-One: action should be an object')

this.store.dispatch(action)
}

Expand All @@ -59,6 +71,9 @@ class Tram {

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

static html(registry) {
if (registry) {
assert.equal(typeof registry, 'object', 'Tram-One: registry should be an object')
assert.ok(!(registry instanceof Array), 'Tram-One: registry should be an object')
}

return rbelRegister(belCreateElement, registry || {})
}
}
Expand Down

0 comments on commit 0115e2f

Please sign in to comment.