11const xtend = require ( 'xtend' )
2+ const assert = require ( 'assert' )
23const nanorouter = require ( 'nanorouter' )
34const belCreateElement = require ( 'bel' ) . createElement
45const rbelRegister = require ( 'rbel' )
@@ -8,6 +9,10 @@ const urlListener = require('url-listener')
89
910class 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