import { Component, Graph, Renderer, Router, mount } from './el-ui.js'; class TodoItem extends Component { constructor(props = {}) { super(); this.props = props; this._graph = new Graph(); this._stateNodes = {}; this._state = {}; // Props this._props_text = props.text !== undefined ? props.text : undefined; this._props_done = props.done !== undefined ? props.done : false; // State nodes (Engram graph seeds) this._stateNodes['completed'] = this._graph.seed({ type: 'state', name: 'completed', content: false }); this._state['completed'] = false; // Subscribe to graph activation events for (const [key, nodeId] of Object.entries(this._stateNodes)) { this._graph.subscribe(nodeId, (node) => { this._state[key] = node.content; if (this._renderer) this._renderer.patch(); }); } } setState(name, value) { if (this._stateNodes[name] !== undefined) { this._graph.update(this._stateNodes[name], value); } } render() { const __self = this; const completed = this._state['completed']; const text = this._props_text; const done = this._props_done; return `
  • ${text }
  • `; } } class TodoApp extends Component { constructor(props = {}) { super(); this.props = props; this._graph = new Graph(); this._stateNodes = {}; this._state = {}; // State nodes (Engram graph seeds) this._stateNodes['newItem'] = this._graph.seed({ type: 'state', name: 'newItem', content: "" }); this._state['newItem'] = ""; this._stateNodes['items'] = this._graph.seed({ type: 'state', name: 'items', content: "" }); this._state['items'] = ""; // Subscribe to graph activation events for (const [key, nodeId] of Object.entries(this._stateNodes)) { this._graph.subscribe(nodeId, (node) => { this._state[key] = node.content; if (this._renderer) this._renderer.patch(); }); } } setState(name, value) { if (this._stateNodes[name] !== undefined) { this._graph.update(this._stateNodes[name], value); } } addItem() { const newItem = this._state['newItem']; const items = this._state['items']; if newItem != "" { items = items + newItem + ";" newItem = "" } } render() { const __self = this; const newItem = this._state['newItem']; const items = this._state['items']; return `

    Todos

    `; } } class App extends Component { constructor(props = {}) { super(); this.props = props; this._graph = new Graph(); this._stateNodes = {}; this._state = {}; } setState(name, value) { if (this._stateNodes[name] !== undefined) { this._graph.update(this._stateNodes[name], value); } } render() { const __self = this; return `
    ${__self._child(TodoApp, { })}
    `; } } export { TodoItem, TodoApp, App }; // Mount the app mount(App, '#app');