From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../architecture-examples/preact/src/app/index.js | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/preact/src/app/index.js (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/preact/src/app/index.js') diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/preact/src/app/index.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/preact/src/app/index.js new file mode 100644 index 0000000000..64390be17d --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/preact/src/app/index.js @@ -0,0 +1,134 @@ +import { h, Component } from 'preact'; +import linkState from 'linkstate'; + +import TodoModel from './model'; +import TodoFooter from './footer'; +import TodoItem from './item'; + +const ENTER_KEY = 13; + +const FILTERS = { + all: todo => true, + active: todo => !todo.completed, + completed: todo => todo.completed +}; + +export default class App extends Component { + constructor() { + super(); + this.model = new TodoModel('preact-todos', () => this.setState({}) ); + addEventListener('hashchange', this.handleRoute.bind(this)); + this.handleRoute(); + } + + handleRoute() { + let nowShowing = String(location.hash || '').split('/').pop(); + if (!FILTERS[nowShowing]) { + nowShowing = 'all'; + } + this.setState({ nowShowing }); + } + + handleNewTodoKeyDown = (e) => { + if (e.keyCode !== ENTER_KEY) return; + e.preventDefault(); + + // let val = ''; + // if (this.state.newTodo === undefined) { + // val = e.target.value.trim(); + // } + + let val = e.target.value.trim(); + + if (val) { + this.model.addTodo(val); + this.setState({ newTodo: '' }); + } + }; + + toggleAll = event => { + let checked = event.target.checked; + this.model.toggleAll(checked); + }; + + toggle = todo => { + this.model.toggle(todo); + }; + + destroy = todo => { + this.model.destroy(todo); + }; + + edit = todo => { + this.setState({ editing: todo.id }); + }; + + save = (todoToSave, text) => { + this.model.save(todoToSave, text); + this.setState({ editing: null }); + }; + + cancel = () => { + this.setState({ editing: null }); + }; + + clearCompleted = () => { + this.model.clearCompleted(); + }; + + render({ }, { nowShowing = ALL_TODOS, newTodo, editing }) { + let { todos } = this.model, + shownTodos = todos.filter( FILTERS[nowShowing] ), + activeTodoCount = todos.reduce( (a, todo) => a + (todo.completed ? 0 : 1), 0), + completedCount = todos.length - activeTodoCount; + + return ( +
+
+

todos

+ +
+ + { todos.length ? ( +
+ +
    + { shownTodos.map( todo => ( + + )) } +
+
+ ) : null } + + { (activeTodoCount || completedCount) ? ( + + ) : null } +
+ ); + } +} -- cgit v1.2.3