-
-
Save Raynos/51b425267dba961d4e52 to your computer and use it in GitHub Desktop.
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
var Element = require("fragment").Element | |
, unpack = require("unpack-element") | |
, partial = require("ap").partial | |
, append = require("insert").append | |
, chain = require("stream-chain") | |
var html = require("todolist.html") | |
, Todo = require("../todo") | |
module.exports = Elements | |
function Elements() { | |
var elements = unpack(Element(html)) | |
elements.appendTodos = appendTodos | |
return elements | |
function appendTodos(todos) { | |
// Map all the todos coming out of the entity to a Todo representation | |
// Make sure we append all the todo elements to the todoList | |
chain(todos) | |
.map(Todo) | |
.pluck("elements.root") | |
.forEach(partial(append, elements.todoList)) | |
} | |
} |
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
var Element = require("fragment").Element | |
, forEach = require("forEach-stream") | |
, append = require("insert").append | |
var html = require("todolist.html") | |
, Todo = require("../todo") | |
module.exports = Elements | |
function Elements() { | |
var elem = Element(html) | |
, elements = { | |
root: elem | |
, todoList: elem.querySelector("#todo-list") | |
, appendTodos: appendTodos | |
} | |
return elements | |
function appendTodos(todos) { | |
forEach(todos, function (todo) { | |
var t = Todo(todo) | |
, root = t.elements.root | |
append(elements.todoList, root) | |
}) | |
} | |
} |
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
var Element = require("fragment").Element | |
, unpack = require("unpack-element") | |
, partial = require("ap").partial | |
, map = require("lazy-map-stream") | |
, forEach = require("forEach-stream") | |
, append = require("insert").append | |
, pluck = require("pluck-stream") | |
var html = require("todolist.html") | |
, Todo = require("../todo") | |
module.exports = Elements | |
function Elements() { | |
var elements = unpack(Element(html)) | |
elements.appendTodos = appendTodos | |
return elements | |
function appendTodos(todos) { | |
// Map all the todos coming out of the entity to a Todo representation | |
var todoItems = map(todos, Todo) | |
, todoEls = pluck(todoItems, "elements.root") | |
// Make sure we append all the todo elements to the todoList | |
forEach(todoEls, partial(append, elements.todoList)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment