-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathsimple-app.js
41 lines (35 loc) · 963 Bytes
/
simple-app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// @ts-check
import {Component, h} from '../../lib';
/**
* @typedef {Object} SimpleAppState
* @property {string} foo
* @property {string} baz
*/
/** @extends {Component<SimpleAppState>} */
export class SimpleApp extends Component {
get config() {
return {
defaultState: {
foo: `bar`,
baz: `qux`,
},
helpers: {
capitalize: (s) => s[0].toUpperCase() + s.slice(1),
},
hooks: {
preUpdate: () => (this.preFoo = this.state.foo),
postUpdate: () => (this.postFoo = this.state.foo),
},
template: (state) =>
h(`div`, {class: {foo: true}}, [
h(`p`, `Value of foo: ${state.foo}`),
h(`p`, `Value of baz: ${state.baz}`),
h(`p`, `Foo capitalized: ${state.$helpers.capitalize(state.foo)}`),
]),
};
}
shouldUpdate(state) {
// I simply refuse to say "Value of foo: meow"
return !!state.foo && state.foo !== `meow`;
}
}