optimize example further (#462)
This commit is contained in:
+15
-1
@@ -1,3 +1,5 @@
|
|||||||
|
var Microbounce = require('microbounce')
|
||||||
|
var Microframe = require('microframe')
|
||||||
var mutate = require('xtend/mutable')
|
var mutate = require('xtend/mutable')
|
||||||
var expose = require('choo-expose')
|
var expose = require('choo-expose')
|
||||||
var css = require('sheetify')
|
var css = require('sheetify')
|
||||||
@@ -47,17 +49,21 @@ function mainView (state, emit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function todoStore (state, emitter) {
|
function todoStore (state, emitter) {
|
||||||
|
// Default values
|
||||||
if (!state.todos) {
|
if (!state.todos) {
|
||||||
state.todos = {}
|
state.todos = {}
|
||||||
|
|
||||||
state.todos.active = []
|
state.todos.active = []
|
||||||
state.todos.done = []
|
state.todos.done = []
|
||||||
state.todos.all = []
|
state.todos.all = []
|
||||||
state.todos.input = ''
|
|
||||||
|
|
||||||
state.todos.idCounter = 0
|
state.todos.idCounter = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always reset when application boots
|
||||||
|
state.todos.input = ''
|
||||||
|
|
||||||
|
// Register emitters after DOM is loaded to speed up DOM loading
|
||||||
emitter.on('DOMContentLoaded', function () {
|
emitter.on('DOMContentLoaded', function () {
|
||||||
emitter.emit('log:debug', 'Loading todos model')
|
emitter.emit('log:debug', 'Loading todos model')
|
||||||
|
|
||||||
@@ -253,6 +259,8 @@ function Footer (state, emit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var debounce = Microbounce(256)
|
||||||
|
var nextFrame = Microframe()
|
||||||
function Header (state, emit) {
|
function Header (state, emit) {
|
||||||
return html`
|
return html`
|
||||||
<header class="header">
|
<header class="header">
|
||||||
@@ -269,10 +277,16 @@ function Header (state, emit) {
|
|||||||
var value = e.target.value
|
var value = e.target.value
|
||||||
if (!value) return
|
if (!value) return
|
||||||
if (e.keyCode === 13) {
|
if (e.keyCode === 13) {
|
||||||
|
nextFrame(function () {
|
||||||
emit('todos:input', '')
|
emit('todos:input', '')
|
||||||
emit('todos:create', value)
|
emit('todos:create', value)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
|
debounce(function () {
|
||||||
|
nextFrame(function () {
|
||||||
emit('todos:input', value)
|
emit('todos:input', value)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
"choo-expose": "^1.0.0",
|
"choo-expose": "^1.0.0",
|
||||||
"choo-log": "^6.0.0",
|
"choo-log": "^6.0.0",
|
||||||
"choo-persist": "^3.0.0",
|
"choo-persist": "^3.0.0",
|
||||||
|
"microbounce": "^1.0.0",
|
||||||
|
"microframe": "^1.0.0",
|
||||||
"sheetify": "^6.0.1",
|
"sheetify": "^6.0.1",
|
||||||
"todomvc-app-css": "^2.0.6",
|
"todomvc-app-css": "^2.0.6",
|
||||||
"todomvc-common": "^1.0.3",
|
"todomvc-common": "^1.0.3",
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ var assert = require('assert')
|
|||||||
var onHistoryChange = require('./lib/history')
|
var onHistoryChange = require('./lib/history')
|
||||||
var onHref = require('./lib/href')
|
var onHref = require('./lib/href')
|
||||||
|
|
||||||
module.exports = Framework
|
module.exports = Choo
|
||||||
|
|
||||||
function Framework (opts) {
|
function Choo (opts) {
|
||||||
opts = opts || {}
|
opts = opts || {}
|
||||||
|
|
||||||
var routerOpts = {
|
var routerOpts = {
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
"deps": "dependency-check --entry ./html.js . && dependency-check . --extra --no-dev --entry ./html.js",
|
"deps": "dependency-check --entry ./html.js . && dependency-check . --extra --no-dev --entry ./html.js",
|
||||||
"inspect": "browserify --full-paths index -g unassertify -g uglifyify | discify --open",
|
"inspect": "browserify --full-paths index -g unassertify -g uglifyify | discify --open",
|
||||||
"prepublish": "npm run build",
|
"prepublish": "npm run build",
|
||||||
"start": "bankai start example --open --optimize",
|
"start": "bankai start example --optimize",
|
||||||
"test": "standard && npm run deps && node test.js"
|
"test": "standard && npm run deps && node test.js"
|
||||||
},
|
},
|
||||||
"repository": "yoshuawuyts/choo",
|
"repository": "yoshuawuyts/choo",
|
||||||
|
|||||||
Reference in New Issue
Block a user