diff --git a/examples/mailbox/elements/email.js b/examples/mailbox/elements/email.js
index 361f37b..04d9815 100644
--- a/examples/mailbox/elements/email.js
+++ b/examples/mailbox/elements/email.js
@@ -4,7 +4,7 @@ module.exports = function (params, state, send) {
const mailbox = params.mailbox
const message = params.message
- const email = state[mailbox + ':messages'].filter(function (msg) {
+ const email = state[mailbox].messages.filter(function (msg) {
return String(msg.id) === message
})[0]
diff --git a/examples/mailbox/elements/mailbox.js b/examples/mailbox/elements/mailbox.js
index e435b2e..23a8f0e 100644
--- a/examples/mailbox/elements/mailbox.js
+++ b/examples/mailbox/elements/mailbox.js
@@ -5,9 +5,10 @@ module.exports = function () {
return function (params, state, send) {
const mailbox = params.mailbox
const message = params.message
+ const messages = state[mailbox].messages
if (message) {
- const email = state[mailbox + ':messages'].filter(function (msg) {
+ const email = state[mailbox].messages.filter(function (msg) {
return String(msg.id) === message
})[0]
@@ -15,7 +16,7 @@ module.exports = function () {
${createHeader()}
- ${state[mailbox + ':messages'].map(function (msg) {
+ ${messages.map(function (msg) {
return createMessage(msg, mailbox)
})}
@@ -28,7 +29,7 @@ module.exports = function () {
return choo.view`
${createHeader()}
- ${state[mailbox + ':messages'].map(function (msg) {
+ ${messages.map(function (msg) {
return createMessage(msg, mailbox)
})}
diff --git a/examples/mailbox/elements/nav.js b/examples/mailbox/elements/nav.js
index 2d51362..249ae80 100644
--- a/examples/mailbox/elements/nav.js
+++ b/examples/mailbox/elements/nav.js
@@ -3,16 +3,15 @@ const choo = require('../../../')
const mailboxes = [ 'inbox', 'spam', 'sent' ]
module.exports = function (params, state, send) {
- const mailbox = params.mailbox
-
return choo.view`
diff --git a/examples/mailbox/elements/pathname.js b/examples/mailbox/elements/pathname.js
index d9eb157..7006900 100644
--- a/examples/mailbox/elements/pathname.js
+++ b/examples/mailbox/elements/pathname.js
@@ -2,9 +2,10 @@ const pathname = require('pathname-match')
const choo = require('../../../')
module.exports = function (params, state, send) {
+ const location = state.app.location
return choo.view`
- URL: ${pathname(state.location) || '/'}
+ URL: ${pathname(location) || '/'}
`
}
diff --git a/examples/mailbox/models/inbox.js b/examples/mailbox/models/inbox.js
index c055a8c..440d852 100644
--- a/examples/mailbox/models/inbox.js
+++ b/examples/mailbox/models/inbox.js
@@ -1,4 +1,5 @@
module.exports = {
+ namespace: 'inbox',
state: {
messages: [
{
diff --git a/examples/mailbox/models/sent.js b/examples/mailbox/models/sent.js
index 0dc4a60..72acae0 100644
--- a/examples/mailbox/models/sent.js
+++ b/examples/mailbox/models/sent.js
@@ -1,4 +1,5 @@
module.exports = {
+ namespace: 'sent',
state: {
messages: [
{
diff --git a/examples/mailbox/models/spam.js b/examples/mailbox/models/spam.js
index 451e74d..754ff55 100644
--- a/examples/mailbox/models/spam.js
+++ b/examples/mailbox/models/spam.js
@@ -1,4 +1,5 @@
module.exports = {
+ namespace: 'spam',
state: {
messages: [
{
diff --git a/index.js b/index.js
index 5edc432..aad8e4e 100644
--- a/index.js
+++ b/index.js
@@ -84,7 +84,7 @@ function choo () {
}
const nsReducers = ns ? reducers[ns] : reducers
- if (nsReducers[action.type]) {
+ if (nsReducers && nsReducers[action.type]) {
if (ns) {
state[ns] = reducers[ns][action.type](action, state[ns])
newState = state
@@ -95,7 +95,7 @@ function choo () {
}
const nsEffects = ns ? effects[ns] : effects
- if (nsEffects) {
+ if (nsEffects && nsEffects[action.type]) {
nsEffects[action.type](action, newState || state)
_effects = true
}
@@ -143,7 +143,7 @@ function appInit (opts) {
if (opts.href !== false) {
model.subscriptions.push(function (send) {
href(function (href) {
- send('location', { location: href })
+ send('app:location', { location: href })
})
})
}
@@ -151,7 +151,7 @@ function appInit (opts) {
if (opts.history !== false) {
model.subscriptions.push(function (send) {
history(function (href) {
- send('location', { location: href })
+ send('app:location', { location: href })
})
})
}
@@ -160,8 +160,7 @@ function appInit (opts) {
// handle href links
function setLocation (action, state) {
- const location = action.location.replace(/#.*/, '')
- return xtend(state, { location: location })
+ return { location: action.location.replace(/#.*/, '') }
}
}