import { Component, Graph, Renderer, Router, mount } from '../../dist/el-ui.js'; class Counter extends Component { constructor(props = {}) { super(); this.props = props; this._graph = new Graph(); this._stateNodes = {}; this._state = {}; this._stateNodes['count'] = this._graph.seed({ type: 'state', name: 'count', content: 0 }); this._state['count'] = 0; this._stateNodes['history'] = this._graph.seed({ type: 'state', name: 'history', content: "" }); this._state['history'] = ""; 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); } } increment() { const __self = this; const count = this._state['count']; const history = this._state['history']; const initialValue = this.props['initialValue'] !== undefined ? this.props['initialValue'] : 0; const label = this.props['label'] !== undefined ? this.props['label'] : "Counter"; __self.setState('count', count + 1) __self.setState('history', history + "+" + count + " ") } decrement() { const __self = this; const count = this._state['count']; const history = this._state['history']; const initialValue = this.props['initialValue'] !== undefined ? this.props['initialValue'] : 0; const label = this.props['label'] !== undefined ? this.props['label'] : "Counter"; __self.setState('count', count - 1) __self.setState('history', history + "-" + count + " ") } reset() { const __self = this; const count = this._state['count']; const history = this._state['history']; const initialValue = this.props['initialValue'] !== undefined ? this.props['initialValue'] : 0; const label = this.props['label'] !== undefined ? this.props['label'] : "Counter"; __self.setState('count', 0) __self.setState('history', "") } render() { const __self = this; const count = this._state['count']; const history = this._state['history']; const initialValue = this.props['initialValue'] !== undefined ? this.props['initialValue'] : 0; const label = this.props['label'] !== undefined ? this.props['label'] : "Counter"; return `

${label }

${count }
${(history != "") ? `
history:${history }
` : ``}${(count == 0) ? `

Press + or - to begin.

` : ``}
`; } } class CounterPair 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(Counter, { label: "Left" })}${__self._child(Counter, { label: "Right" })}
`; } } 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 `

el-ui SSR + Hydration

Server-rendered, client-hydrated with spreading activation

${__self._child(Counter, { label: "Main Counter" })}${__self._child(CounterPair, { })}
`; } } export { Counter, CounterPair, App };