Skip to content

Commit fa28a77

Browse files
committed
upd
1 parent b3e50aa commit fa28a77

3 files changed

Lines changed: 52 additions & 27 deletions

File tree

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [E4X](./overview/e4x.md)
1212
- [Whack DS](./overview/whack_ds.md)
1313
- [MXML like constructs](./overview/whack_ds/mxml_like.md)
14+
- [The good, the bad](./overview/whack_ds/good_bad.md)
1415
- [Tooling](./overview/tooling.md)
1516
- [Namespaces](./overview/namespaces.md)
1617
- [Event model](./overview/event-model.md)

src/overview/whack_ds.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,7 @@ Even though the constructor is frequently re-evaluated, objects originating from
102102

103103
## Immutability
104104

105-
Because of possible inconsistencies when reading or comparing States, Contexts and Props, which may also affect `<fx:Style>` elements, it is best to treat those as immutable (e.g. not to overwrite any field or element of a Prop, Context or State). Overwriting a field or element of such a thing involves rather overwriting the whole thing, such as:
106-
107-
```sx
108-
[State]
109-
var x : [double] = [];
110-
111-
// Somewhere
112-
113-
x = [...x, 10] // pushes 10
114-
// never .push(10)
115-
```
116-
117-
In the same component, you may also define deriveds, like:
118-
119-
```sx
120-
public function add(n:double):void {
121-
x = [...x, n]
122-
}
123-
```
124-
125-
Then you can do:
126-
127-
```sx
128-
add(10)
129-
```
130-
131-
Anywhere in the component, although this is an insignificant example of how deriveds can be used.
105+
Ensure you follow immutability principles with States, Contexts and Props.
132106

133107
> **Note**: ReactJS and Adobe Flex also present the same limitation.
134108
>

src/overview/whack_ds/good_bad.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# The good, the bad
2+
3+
## :&#x28; Mutability
4+
5+
```sx
6+
[State]
7+
var x : [uint] = [];
8+
9+
x.push(10); // BAD
10+
```
11+
12+
## :&#x29; Mutability
13+
14+
```sx
15+
[State]
16+
var x : [uint] = [];
17+
18+
x = [...x, 10] // GOOD
19+
```
20+
21+
<sup>You can also implement deriveds.</sup>
22+
23+
## :&#x28; Callbacks
24+
25+
```sx
26+
final = (
27+
<cset:Evaluator
28+
functions={[ function():uint(10)
29+
, function():uint (0) ]}/>
30+
) // BAD
31+
```
32+
33+
<sup>Callback caching (`whack.ds.useCallback`) only occurs implicitly for Functions assigned to the whole attribute.</sup>
34+
35+
## :&#x28; Callbacks
36+
37+
```sx
38+
final = (
39+
<cset:Evaluator>
40+
<cset:functions>
41+
{[
42+
function():uint (10), // BAD
43+
function():uint (0), // BAD
44+
]}
45+
</cset:functions>
46+
</cset:Evaluator>
47+
)
48+
```
49+
50+
<sup>Callback caching (`whack.ds.useCallback`) only occurs implicitly for Functions assigned to the whole attribute.</sup>

0 commit comments

Comments
 (0)