-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathInstanceable.njs
More file actions
76 lines (64 loc) · 1.69 KB
/
Instanceable.njs
File metadata and controls
76 lines (64 loc) · 1.69 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Nullstack from 'nullstack'
class Instanceable extends Nullstack {
title = {
title: 'Nullstack!',
prepare: 'Prepared!',
hydrate: 'Hydrated!',
}
serverLoaded = false
static async getData() {
return 'Nullstack! Nullstack!'
}
async changeInstance({ thisInstances, title }) {
const { instanceable } = thisInstances
instanceable.title[title] += ` ${instanceable.title[title]}`
}
prepare({ instances }) {
this.changeInstance({
thisInstances: instances,
title: 'prepare',
})
}
async hydrate({ instances }) {
this.changeInstance({
thisInstances: instances,
title: 'hydrate',
})
}
async customMethod({ instances }) {
const title = await this.getData()
const { instanceable } = instances
instanceable.title.title = title
instanceable.serverLoaded = true
}
renderTitle({ title }) {
return (
title[0] !== '_isProxy' && (
<p data-title={title[0]} data-hydrated={this.hydrated}>
{this.title[title[0]]}
</p>
)
)
}
render({ instances }) {
const { application } = instances
const mainHasKey = application && typeof application.changeInstanceable === 'function'
return (
<div>
{application && (
<button data-change-instanceable={this.serverLoaded} onclick={application.changeInstanceable}>
Mess with "instanceable" from Main
</button>
)}
<div>
{Object.entries(this.title).map((title) => (
<Title title={title} />
))}
</div>
<p data-application-key={mainHasKey} />
<div data-key={this.key} />
</div>
)
}
}
export default Instanceable