|
1 | 1 | function Table(data, ...args) { |
2 | | - return h._( |
3 | | - h.table( |
4 | | - { class: "table" }, |
5 | | - h.tbody(each(data, (value) => h.Row(value))), |
6 | | - ...args |
7 | | - ), |
8 | | - ); |
| 2 | + return h._( |
| 3 | + h.table( |
| 4 | + { class: "table" }, |
| 5 | + h.tbody(each(data, (value) => h.Row(value))), |
| 6 | + ...args |
| 7 | + ) |
| 8 | + ); |
9 | 9 | } |
10 | 10 |
|
11 | 11 | function Row(columns, ...args) { |
12 | | - return h.$( |
13 | | - h.tr( |
14 | | - each(columns, (value) => h.Column(value)), |
15 | | - ...args |
16 | | - ) |
17 | | - ); |
| 12 | + return h.$( |
| 13 | + h.tr( |
| 14 | + each(columns, (value) => h.Column(value)), |
| 15 | + ...args |
| 16 | + ) |
| 17 | + ); |
18 | 18 | } |
19 | 19 |
|
20 | | - |
21 | | - |
22 | 20 | function Column(data, ...args) { |
23 | | - return h._(h.td(data, ...args)); |
| 21 | + return h._(h.td(data, ...args)); |
24 | 22 | } |
25 | 23 |
|
26 | 24 | class App extends OpenScript.Component { |
27 | | - async mount() { |
28 | | - await super.mount(); |
29 | | - req("MainNav"); |
30 | | - req("Blog.List"); |
31 | | - req("Counter"); |
32 | | - req("Chart"); |
33 | | - } |
34 | | - |
35 | | - render(...args) { |
36 | | - return h.div( |
37 | | - h.MainNav(), |
38 | | - |
39 | | - h.div( |
40 | | - { class: "container py-3" }, |
41 | | - |
42 | | - h.header( |
43 | | - { |
44 | | - class: "mb-3", |
45 | | - }, |
46 | | - |
47 | | - h.h1("The Blog List Header"), |
48 | | - h.hr() |
49 | | - ), |
50 | | - |
51 | | - h.div( |
52 | | - { |
53 | | - class: "card mb-3", |
54 | | - }, |
55 | | - h.div({ class: "card-header" }, "Uses Anonymous Component"), |
56 | | - h.div( |
57 | | - { class: "card-body " }, |
58 | | - |
59 | | - h.p( |
60 | | - { |
61 | | - class: "card-text", |
62 | | - }, |
63 | | - |
64 | | - `I will not change: (`, |
65 | | - |
66 | | - h.b(Math.floor(Math.random() * 1000)), |
67 | | - |
68 | | - `) because I am not re-rendered`, |
69 | | - |
70 | | - h.br(), |
71 | | - |
72 | | - `I will change: (`, |
73 | | - h.b(v(context("blogCxt").counter)), |
74 | | - `) because I am re-rendered when the number changes. `, |
75 | | - h.b(`Actually, only the number is re-rendered, not this text.`) |
76 | | - ) |
77 | | - ) |
78 | | - ), |
79 | | - |
80 | | - h.BlogCounter(context("blogCxt").counter, { |
81 | | - class: "p-1", |
82 | | - }), |
83 | | - |
84 | | - h.Chart({ |
85 | | - class: "mb-3", |
86 | | - }), |
87 | | - |
88 | | - h.BlogList( |
89 | | - context("blogCxt").blogs, |
90 | | - context("blogCxt").counter, |
91 | | - "I am a blog List. I re-render when counter changes" |
92 | | - ), |
93 | | - |
94 | | - h.BlogList( |
95 | | - context("blogCxt").blogs, |
96 | | - { value: 0 }, |
97 | | - "I am the same blog list. I do not re-render when counter changes because I do not listen its changes." |
98 | | - ), |
99 | | - |
100 | | - h.Table([ |
101 | | - [1, 2, 3], |
102 | | - [4, 5, 6], |
103 | | - [7, 8, 9], |
104 | | - ]) |
105 | | - ), |
106 | | - |
107 | | - ...args |
108 | | - ); |
109 | | - } |
110 | | - |
111 | | - $$namespace = { |
112 | | - hello: () => { |
113 | | - console.log("namespace:hello called"); |
114 | | - this.instanceMethod(); |
115 | | - }, |
116 | | - |
117 | | - hi: () => { |
118 | | - console.log("namespace:hi called"); |
119 | | - this.instanceMethod(); |
120 | | - }, |
121 | | - |
122 | | - $$sns: { |
123 | | - hello: () => { |
124 | | - console.log("namespace:sns:hello called"); |
125 | | - this.instanceMethod(); |
126 | | - }, |
127 | | - |
128 | | - hi: () => { |
129 | | - console.log("namespace:sns:hi called"); |
130 | | - this.instanceMethod(); |
131 | | - }, |
132 | | - }, |
133 | | - }; |
134 | | - |
135 | | - instanceMethod() { |
136 | | - console.log(`Instance Method Accessed`); |
137 | | - } |
| 25 | + async mount() { |
| 26 | + await super.mount(); |
| 27 | + req("MainNav"); |
| 28 | + req("Blog.List"); |
| 29 | + req("Counter"); |
| 30 | + req("Chart"); |
| 31 | + } |
| 32 | + |
| 33 | + render(...args) { |
| 34 | + return h.div( |
| 35 | + h.MainNav(), |
| 36 | + |
| 37 | + h.div( |
| 38 | + { class: "container py-3" }, |
| 39 | + |
| 40 | + h.header( |
| 41 | + { |
| 42 | + class: "mb-3", |
| 43 | + }, |
| 44 | + |
| 45 | + h.h1("The Blog List Header"), |
| 46 | + h.hr() |
| 47 | + ), |
| 48 | + |
| 49 | + h.div( |
| 50 | + { |
| 51 | + class: "card mb-3", |
| 52 | + }, |
| 53 | + h.div({ class: "card-header" }, "Uses Anonymous Component"), |
| 54 | + h.div( |
| 55 | + { class: "card-body " }, |
| 56 | + |
| 57 | + h.p( |
| 58 | + { |
| 59 | + class: "card-text", |
| 60 | + }, |
| 61 | + |
| 62 | + `I will not change: (`, |
| 63 | + |
| 64 | + h.b(Math.floor(Math.random() * 1000)), |
| 65 | + |
| 66 | + `) because I am not re-rendered`, |
| 67 | + |
| 68 | + h.br(), |
| 69 | + |
| 70 | + `I will change: (`, |
| 71 | + h.b(v(context("blogCxt").counter)), |
| 72 | + `) because I am re-rendered when the number changes. `, |
| 73 | + h.b( |
| 74 | + `Actually, only the number is re-rendered, not this text.` |
| 75 | + ) |
| 76 | + ) |
| 77 | + ) |
| 78 | + ), |
| 79 | + |
| 80 | + h.BlogCounter(context("blogCxt").counter, { |
| 81 | + class: "p-1", |
| 82 | + }), |
| 83 | + |
| 84 | + h.Chart({ |
| 85 | + class: "mb-3", |
| 86 | + }), |
| 87 | + |
| 88 | + h.BlogList( |
| 89 | + context("blogCxt").blogs, |
| 90 | + context("blogCxt").counter, |
| 91 | + "I am a blog List. I re-render when counter changes" |
| 92 | + ), |
| 93 | + |
| 94 | + h.BlogList( |
| 95 | + context("blogCxt").blogs, |
| 96 | + { value: 0 }, |
| 97 | + "I am the same blog list. I do not re-render when counter changes because I do not listen its changes." |
| 98 | + ), |
| 99 | + |
| 100 | + h.Table([ |
| 101 | + [1, 2, 3], |
| 102 | + [4, 5, 6], |
| 103 | + [7, 8, 9], |
| 104 | + ]) |
| 105 | + ), |
| 106 | + |
| 107 | + ...args |
| 108 | + ); |
| 109 | + } |
| 110 | + |
| 111 | + $$namespace = { |
| 112 | + hello: () => { |
| 113 | + console.log("namespace:hello called"); |
| 114 | + this.instanceMethod(); |
| 115 | + }, |
| 116 | + |
| 117 | + hi: () => { |
| 118 | + console.log("namespace:hi called"); |
| 119 | + this.instanceMethod(); |
| 120 | + }, |
| 121 | + |
| 122 | + $$sns: { |
| 123 | + hello: () => { |
| 124 | + console.log("namespace:sns:hello called"); |
| 125 | + this.instanceMethod(); |
| 126 | + }, |
| 127 | + |
| 128 | + hi: () => { |
| 129 | + console.log("namespace:sns:hi called"); |
| 130 | + this.instanceMethod(); |
| 131 | + }, |
| 132 | + }, |
| 133 | + }; |
| 134 | + |
| 135 | + instanceMethod() { |
| 136 | + console.log(`Instance Method Accessed`); |
| 137 | + } |
138 | 138 | } |
0 commit comments