You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dsl-client/hyper-component.md
+38-39Lines changed: 38 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -222,7 +222,7 @@ Parent { Child() }
222
222
param :items
223
223
render do
224
224
# notice how the items param is accessed in CamelCase (to indicate that it is read-only)
225
-
@Items.each do |item|
225
+
items.each do |item|
226
226
PARAdo
227
227
item[:text]
228
228
end
@@ -241,7 +241,7 @@ The situation gets more complicated when the children are shuffled around (as in
241
241
param :results, type: [Hash] # each result is a hash of the form {id: ..., text: ....}
242
242
render do
243
243
OLdo
244
-
@Results.each do |result|
244
+
results.each do |result|
245
245
LI(key: result[:id]) { result[:text] }
246
246
end
247
247
end
@@ -257,15 +257,15 @@ The `key` should *always* be supplied directly to the components in the array, n
257
257
classListItemWrapper < HyperComponent
258
258
param :data
259
259
render do
260
-
LI(key:@Data[:id]) { @Data[:text] }
260
+
LI(key:data[:id]) { data[:text] }
261
261
end
262
262
end
263
263
264
264
classMyComponent < HyperComponent
265
265
param :results
266
266
render do
267
267
ULdo
268
-
@Result.each do |result|
268
+
result.each do |result|
269
269
ListItemWrapperdata: result
270
270
end
271
271
end
@@ -278,15 +278,15 @@ end
278
278
classListItemWrapper < HyperComponent
279
279
param :data
280
280
render do
281
-
LI { @Data[:text] }
281
+
LI { data[:text] }
282
282
end
283
283
end
284
284
285
285
classMyComponent < HyperComponent
286
286
param :results
287
287
render do
288
288
ULdo
289
-
@Result.each do |result|
289
+
results.each do |result|
290
290
ListItemWrapperkey: result[:id], data: result
291
291
end
292
292
end
@@ -316,7 +316,7 @@ class IndentEachLine < HyperComponent
316
316
317
317
render(DIV) do
318
318
children.each_with_index do |child, i|
319
-
child.render(style: {"margin-left" => @By*i})
319
+
child.render(style: {"margin-left" => by*i})
320
320
end
321
321
end
322
322
end
@@ -336,10 +336,9 @@ When designing interfaces, break down the common design elements (buttons, form
336
336
337
337
## Params
338
338
339
-
The `param` method gives *read-only* access to each of the scalar params passed to the Component. The params are accessed as instance variables converted to CamelCase.
339
+
The `param` method gives *read-only* access to each of the scalar params passed to the Component. Params are accessed as instance methods on the Component.
340
340
341
-
Within a React Component the `param` method is used to define the parameter signature of the component. You can think of params as
342
-
the values that would normally be sent to the instance's `initialize` method, but with the difference that a React Component gets new parameters when it is re-rendered.
341
+
Within a React Component the `param` method is used to define the parameter signature of the component. You can think of params as the values that would normally be sent to the instance's `initialize` method, but with the difference that a React Component gets new parameters when it is re-rendered.
343
342
344
343
Note that the default value can be supplied either as the hash value of the symbol, or explicitly using the `:default_value` key.
345
344
@@ -358,7 +357,7 @@ param foo: [], type: [String] # foo must be an array of strings, and has a
358
357
359
358
#### Accessing param values
360
359
361
-
> Params are accessible in the Component class as instance variables in **CamelCase**. The CamelCase syntax is used to indicate that params are immutable.
360
+
Params are accessible in the Component class as instance methods.
362
361
363
362
For example:
364
363
@@ -368,7 +367,7 @@ class Hello < HyperComponent
368
367
param visitor:"World", type:String
369
368
370
369
render do
371
-
"Hello #{@Visitor}"# notice how you CamelCase for immutable params
370
+
"Hello #{visitor}"
372
371
end
373
372
end
374
373
```
@@ -389,8 +388,8 @@ class Likes < HyperComponent
389
388
param :book# book is an instance of the Book model
390
389
391
390
render(DIV) do
392
-
P { "#{@Book.likes.count} likes" }
393
-
BUTTON { "Like" }.on(:click) { @Book.likes +=1}
391
+
P { "#{book.likes.count} likes" }
392
+
BUTTON { "Like" }.on(:click) { book.likes +=1}
394
393
end
395
394
end
396
395
```
@@ -433,7 +432,7 @@ A Ruby `Proc` can be passed to a component like any other object. A param of ty
433
432
param :all_done, type:Proc
434
433
...
435
434
# typically in an event handler
436
-
params.all_done(data)# instead of params.all_done.call(data)
435
+
all_done(data).call
437
436
```
438
437
439
438
Proc params can be optional, using the `default: nil` and `allow_nil: true` options. Invoking a nil proc param will do nothing. This is handy for allowing optional callbacks.
@@ -445,8 +444,8 @@ class Alarm < HyperComponent
445
444
446
445
after_mount do
447
446
@clock= every(1) do
448
-
ifTime.now >@At
449
-
@Notify
447
+
ifTime.now >at
448
+
notify.call
450
449
@clock.stop
451
450
end
452
451
force_update!
@@ -475,7 +474,7 @@ class ButtonBar < HyperComponent
475
474
param :button
476
475
477
476
render do
478
-
@Button.render
477
+
button.render
479
478
end
480
479
end
481
480
```
@@ -491,10 +490,10 @@ class Test < HyperComponent
491
490
render do
492
491
DIVdo
493
492
children.each do |child|
494
-
@Node.render
493
+
node.render
495
494
child.render
496
495
end
497
-
@Node.render
496
+
node.render
498
497
end
499
498
end
500
499
end
@@ -511,7 +510,7 @@ class CheckLink < HyperComponent
0 commit comments