examples: update mailbox

This commit is contained in:
Yoshua Wuyts
2016-05-23 04:00:29 +09:00
parent 24b9be7c8d
commit 300b6325a9
10 changed files with 22 additions and 19 deletions
+3 -3
View File
@@ -6,9 +6,9 @@ sf('tachyons')
const app = choo() const app = choo()
app.model('inbox', require('./models/inbox')) app.model(require('./models/inbox'))
app.model('spam', require('./models/spam')) app.model(require('./models/spam'))
app.model('sent', require('./models/sent')) app.model(require('./models/sent'))
app.router((route) => [ app.router((route) => [
route('/', require('./views/empty')), route('/', require('./views/empty')),
+1 -1
View File
@@ -3,7 +3,7 @@ const choo = require('../../../')
module.exports = function (params, state, send) { module.exports = function (params, state, send) {
const mailbox = params.mailbox const mailbox = params.mailbox
const messages = state[mailbox + ':messages'] const messages = state[mailbox].messages
return choo.view` return choo.view`
<div> <div>
<div class="db cf w-100"> <div class="db cf w-100">
+1 -1
View File
@@ -4,7 +4,7 @@ module.exports = function (params, state, send) {
const mailbox = params.mailbox const mailbox = params.mailbox
const message = params.message 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 return String(msg.id) === message
})[0] })[0]
+4 -3
View File
@@ -5,9 +5,10 @@ module.exports = function () {
return function (params, state, send) { return function (params, state, send) {
const mailbox = params.mailbox const mailbox = params.mailbox
const message = params.message const message = params.message
const messages = state[mailbox].messages
if (message) { if (message) {
const email = state[mailbox + ':messages'].filter(function (msg) { const email = state[mailbox].messages.filter(function (msg) {
return String(msg.id) === message return String(msg.id) === message
})[0] })[0]
@@ -15,7 +16,7 @@ module.exports = function () {
<section class="fl mt4 w-80 db"> <section class="fl mt4 w-80 db">
<div> <div>
${createHeader()} ${createHeader()}
${state[mailbox + ':messages'].map(function (msg) { ${messages.map(function (msg) {
return createMessage(msg, mailbox) return createMessage(msg, mailbox)
})} })}
</div> </div>
@@ -28,7 +29,7 @@ module.exports = function () {
return choo.view` return choo.view`
<section class="fl mt4 w-80 db"> <section class="fl mt4 w-80 db">
${createHeader()} ${createHeader()}
${state[mailbox + ':messages'].map(function (msg) { ${messages.map(function (msg) {
return createMessage(msg, mailbox) return createMessage(msg, mailbox)
})} })}
</section> </section>
+3 -4
View File
@@ -3,16 +3,15 @@ const choo = require('../../../')
const mailboxes = [ 'inbox', 'spam', 'sent' ] const mailboxes = [ 'inbox', 'spam', 'sent' ]
module.exports = function (params, state, send) { module.exports = function (params, state, send) {
const mailbox = params.mailbox
return choo.view` return choo.view`
<aside class="fl mt4 w-20 db"> <aside class="fl mt4 w-20 db">
<ul> <ul>
<li> <li>
<h2 class="f4 b lh0">Mailbox</h2> <h2 class="f4 b lh0">Mailbox</h2>
</li> </li>
${mailboxes.map(function (name) { ${mailboxes.map(function (mailbox) {
return createLi(name, state[name + ':messages'], mailbox) const messages = mailbox.messages
return createLi(mailbox, messages, mailbox)
})} })}
</ul> </ul>
</aside> </aside>
+2 -1
View File
@@ -2,9 +2,10 @@ const pathname = require('pathname-match')
const choo = require('../../../') const choo = require('../../../')
module.exports = function (params, state, send) { module.exports = function (params, state, send) {
const location = state.app.location
return choo.view` return choo.view`
<span class="fl mt4 w-100 f4 b"> <span class="fl mt4 w-100 f4 b">
URL: ${pathname(state.location) || '/'} URL: ${pathname(location) || '/'}
</span> </span>
` `
} }
+1
View File
@@ -1,4 +1,5 @@
module.exports = { module.exports = {
namespace: 'inbox',
state: { state: {
messages: [ messages: [
{ {
+1
View File
@@ -1,4 +1,5 @@
module.exports = { module.exports = {
namespace: 'sent',
state: { state: {
messages: [ messages: [
{ {
+1
View File
@@ -1,4 +1,5 @@
module.exports = { module.exports = {
namespace: 'spam',
state: { state: {
messages: [ messages: [
{ {
+5 -6
View File
@@ -84,7 +84,7 @@ function choo () {
} }
const nsReducers = ns ? reducers[ns] : reducers const nsReducers = ns ? reducers[ns] : reducers
if (nsReducers[action.type]) { if (nsReducers && nsReducers[action.type]) {
if (ns) { if (ns) {
state[ns] = reducers[ns][action.type](action, state[ns]) state[ns] = reducers[ns][action.type](action, state[ns])
newState = state newState = state
@@ -95,7 +95,7 @@ function choo () {
} }
const nsEffects = ns ? effects[ns] : effects const nsEffects = ns ? effects[ns] : effects
if (nsEffects) { if (nsEffects && nsEffects[action.type]) {
nsEffects[action.type](action, newState || state) nsEffects[action.type](action, newState || state)
_effects = true _effects = true
} }
@@ -143,7 +143,7 @@ function appInit (opts) {
if (opts.href !== false) { if (opts.href !== false) {
model.subscriptions.push(function (send) { model.subscriptions.push(function (send) {
href(function (href) { href(function (href) {
send('location', { location: href }) send('app:location', { location: href })
}) })
}) })
} }
@@ -151,7 +151,7 @@ function appInit (opts) {
if (opts.history !== false) { if (opts.history !== false) {
model.subscriptions.push(function (send) { model.subscriptions.push(function (send) {
history(function (href) { history(function (href) {
send('location', { location: href }) send('app:location', { location: href })
}) })
}) })
} }
@@ -160,8 +160,7 @@ function appInit (opts) {
// handle href links // handle href links
function setLocation (action, state) { function setLocation (action, state) {
const location = action.location.replace(/#.*/, '') return { location: action.location.replace(/#.*/, '') }
return xtend(state, { location: location })
} }
} }