Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge
m.mount
+ m.redraw
, update router
Simplifies the router and redraw mechanism, and makes it much easier to keep predictable. Bundle size down to 9433 bytes min+gzip, docs updated accordingly.
- Loading branch information
1 parent
9b1b429
commit 755ddb1
Showing
20 changed files
with
512 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use strict" | ||
|
||
var Vnode = require("../render/vnode") | ||
var coreRenderer = require("../render/render") | ||
|
||
module.exports = function($window, schedule, console) { | ||
var renderService = coreRenderer($window) | ||
var subscriptions = [] | ||
var rendering = false | ||
var pending = false | ||
|
||
function sync() { | ||
if (rendering) throw new Error("Nested m.redraw.sync() call") | ||
rendering = true | ||
for (var i = 0; i < subscriptions.length; i += 2) { | ||
try { renderService.render(subscriptions[i], Vnode(subscriptions[i + 1])) } | ||
catch (e) { console.error(e) } | ||
} | ||
rendering = false | ||
} | ||
function redraw() { | ||
if (!pending) { | ||
pending = true | ||
schedule(function() { | ||
pending = false | ||
sync() | ||
}) | ||
} | ||
} | ||
|
||
redraw.sync = sync | ||
renderService.setRedraw(redraw) | ||
|
||
function mount(root, component) { | ||
if (component != null && component.view == null && typeof component !== "function") { | ||
throw new TypeError("m.mount(element, component) expects a component, not a vnode") | ||
} | ||
|
||
var index = subscriptions.indexOf(root) | ||
if (index >= 0) { | ||
subscriptions.splice(index, 2) | ||
renderService.render(root, []) | ||
} | ||
|
||
if (component != null) { | ||
subscriptions.push(root, component) | ||
renderService.render(root, Vnode(component)) | ||
} | ||
} | ||
|
||
return {mount: mount, redraw: redraw} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.