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
import createStore from 'redux-zero'; | |
const initialState = { route: '', todoList: [] }; | |
const store = createStore(initialState); | |
export default store; | |
import store from './store'; | |
function actionCreator(action) { | |
return function() { | |
let state = store.getState(); | |
state = action(state, ...arguments); | |
store.setState(state); |
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
// todoList.js | |
render() { | |
... | |
const todoItems = todoList | |
.filter(todo => { | |
return ( | |
route === '' || | |
(route === 'completed' && todo.completed) || | |
(route === 'active' && !todo.completed) | |
); |
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
render() { | |
const todo = this.todo; | |
const classCompleted = todo.completed ? ' completed' : ''; | |
const inputToggle = todo.completed | |
? html`<input class="toggle" type="checkbox" checked>` | |
: html`<input class="toggle" type="checkbox">`; | |
const classEditing = this._editing ? ' editing' : ''; | |
return html` | |
${style} | |
<div data-id$="${todo.id}" class$="${'item' + |
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
import { toggle, remove, replace } from '../libs/actions'; | |
... | |
class TodoItem extends LitRender(HTMLElement) { | |
... | |
connectedCallback() { | |
const root = this.shadowRoot; | |
... | |
root.addEventListener('click', handlers.onClick); | |
... | |
} |
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
import { render } from '../../node_modules/lit-html/lib/lit-extended'; | |
export default base => | |
class extends base { | |
render() {} | |
async invalidate(instant) { | |
if (!this.needsRender) { | |
if (!instant) { | |
this.needsRender = true; | |
await 0; | |
this.needsRender = false; |
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
customElements.define('todo-app', TodoApp); |
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
... | |
render() { | |
return html` | |
<style> | |
host: { | |
display: block; | |
} | |
section { | |
background: #fff; | |
margin: 130px 0 40px 0; |
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
... | |
add(title) { | |
add(title); | |
} | |
... | |
get length() { | |
const todoList = store.getState().todoList; | |
return todoList.length; | |
} | |
... |
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
... | |
class TodoApp extends LitRender(HTMLElement) { | |
constructor(name) { | |
super(); | |
this.attachShadow({ mode: 'open' }); | |
this.invalidate(); | |
} | |
... |
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
import { html } from 'lit-html'; | |
import LitRender from '../libs/litRender'; | |
import store from '../libs/store'; | |
import { | |
add, | |
toggle, | |
remove, | |
toggleAll, | |
clearCompleted, | |
replace |