Skip to content

Commit 070bdf0

Browse files
feat(overmind): fix onInitialize, also fix website marksy dependency
1 parent eb3341e commit 070bdf0

29 files changed

+769
-67
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"express": "4.16.3",
3333
"install": "0.12.1",
3434
"is-plain-object": "2.0.4",
35-
"marksy": "6.0.3",
35+
"marksy": "^6.1.0",
3636
"npm": "6.3.0",
3737
"page": "1.8.6",
3838
"prismjs": "1.15.0",

packages/node_modules/overmind/src/index.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,19 +423,26 @@ export default class App<
423423

424424
const initializers = this.getInitializers(configuration)
425425

426-
if (initializers.length === 1 && initializers[0].name === 'onInitialize') {
427-
const onInitialize = action().compose(initializers[0])
428-
429-
// @ts-ignore
430-
onInitialize.displayName = 'onInitialize'
431-
onInitialize(undefined)
432-
} else if (initializers.length) {
433-
const onInitialize = action().parallel(initializers)
434-
435-
// @ts-ignore
436-
onInitialize.displayName = 'onInitialize'
437-
onInitialize(undefined)
426+
if (!initializers.length) {
427+
return
438428
}
429+
430+
const rootInitializer =
431+
initializers[0].name === 'onInitialize' ? initializers.shift() : null
432+
433+
let onInitialize = action()
434+
435+
if (initializers.length) {
436+
onInitialize = onInitialize.parallel(initializers)
437+
}
438+
439+
if (rootInitializer) {
440+
onInitialize = onInitialize.compose(rootInitializer)
441+
}
442+
443+
// @ts-ignore
444+
onInitialize.displayName = 'onInitialize'
445+
onInitialize(undefined)
439446
}
440447
private initializeDevtools(host, actionChain, eventHub, proxyStateTree) {
441448
const devtools = new Devtools()

packages/overmind-website/api/action.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Action
22

33
```marksy
4-
<Example name="api/action" />
4+
h(Example, { name: "api/action"})
55
```
66

77
An action allows you to compose pieces of logic into an execution. You typically execute an action based on some user interaction in your application, but it could be everything from a route change to a websocket message as well.
@@ -10,9 +10,16 @@ Actions are defined with a powerful chaining API which gives control of the exec
1010

1111
The action is built up by **operators**, methods called on the action itself. These operators describes the execution logic.
1212

13+
## compose
14+
```marksy
15+
h(Example, { name: "api/action_compose" })
16+
```
17+
18+
Typically used to merge in a separate action. This action will runs as if it was defined with the source action.
19+
1320
## debounce
1421
```marksy
15-
<Example name="api/action_debounce" />
22+
h(Example, { name: "api/action_debounce" })
1623
```
1724

1825
Typically used to only continue execution of the last action call if multiple action calls has been made in the time limit passed in.
@@ -21,7 +28,7 @@ The only argument is the time limit in milliseconds the operator should prevent
2128

2229
## do
2330
```marksy
24-
<Example name="api/action_do" />
31+
h(Example, { name: "api/action_do" })
2532
```
2633

2734
Typically used to fire off an effect without caring about its returned result, if any.
@@ -30,7 +37,7 @@ Only argument is a function that receives the **effects** registered in the appl
3037

3138
## filter
3239
```marksy
33-
<Example name="api/action_filter" />
40+
h(Example, { name: "api/action_filter" })
3441
```
3542

3643
Typically used to stop execution related to some condition.
@@ -39,7 +46,7 @@ The first argument is a function that receives the **effects** registered in the
3946

4047
## fork
4148
```marksy
42-
<Example name="api/action_fork" />
49+
h(Example, { name: "api/action_fork" })
4350
```
4451
Typically used to fork out execution when a value can result in multiple complex executions.
4552

@@ -48,7 +55,7 @@ The first argument is a function that receives the **effects** as the first argu
4855

4956
## map
5057
```marksy
51-
<Example name="api/action_map" />
58+
h(Example, { name: "api/action_map" })
5259
```
5360

5461
Typically used to get values from an effect or transform the current value of the action.
@@ -57,16 +64,25 @@ Only argument is a function that receives the **effects** registered in the appl
5764

5865
## mutate
5966
```marksy
60-
<Example name="api/action_mutation" />
67+
h(Example, { name: "api/action_mutation" })
6168
```
6269

6370
Used to change the state of the application.
6471

6572
Only argument is a function that receives the **state** as the first argument and the current **value** of the action as the second argument. This operator is the only operator that is allowed to mutate the state of the application.
6673

74+
## parallel
75+
```marksy
76+
h(Example, { name: "api/action_parallel" })
77+
```
78+
79+
Typically used to run multiple composed actions in parallel. "In parallel" means that one executes after the other synchronously, but if any of them are doing something asynchronous the execution of the source action will not continue until all of them are done.
80+
81+
The parallel operator does not return a value.
82+
6783
## try
6884
```marksy
69-
<Example name="api/action_try" />
85+
h(Example, { name: "api/action_try" })
7086
```
7187

7288
Typically used to explicitly handle potentially thrown errors from an effect.
@@ -75,7 +91,7 @@ The first argument is a function that receives the **effects** registered in the
7591

7692
## when
7793
```marksy
78-
<Example name="api/action_when" />
94+
h(Example, { name: "api/action_when" })
7995
```
8096

8197
Typically used to fork execution based on a thruthy or falsy value.

packages/overmind-website/api/app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
The **App** class is used to create the application instance. The instance itself exposes a **connect** function used to connect views to the state of the application and allow them to trigger actions. Following is a simple example to show you the structure.
44

55
```marksy
6-
<Example name="api/app_initialize" view />
6+
h(Example, { name: "api/app_initialize", view: true })
77
```

packages/overmind-website/api/compute.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Compute
22

33
```marksy
4-
<Example name="api/compute" view/>
4+
h(Example, { name: "api/compute", view: true })
55
```
66

77
You can add computed state values. These state values are functions that takes one argument, `filterNameBy` in the example above. This argument can be whatever you want, but it can only be a single argument. That means if you want to pass in multiple values you would pass those as part of an object. The reason computed state values work like this is because this argument is the cache key. As long as you pass in the same argument and the accessed state is not changed, the cached value is instantly returned.

packages/overmind-website/api/connect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Connect
22

33
```marksy
4-
<Example name="api/connect" view/>
4+
h(Example, { name: "api/connect", view: true })
55
```
66

77
When you instantiate an Overmind application it exposes the ability to connect components to the state and actions defined. This is simply done by using the **connect** function and pass in the component.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Derive
22

33
```marksy
4-
<Example name="api/derive" view />
4+
h(Example, { name: "api/derive", view: true })
55
```
66

77
You can add derived state to your application. You access derived state like any other value, there is not need to call it as a function. The derived value is cached and will only update when any accessed state changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Effects
22

33
```marksy
4-
<Example name="api/effects" />
4+
h(Example, { name: "api/effects" })
55
```
66

77
There is really no API with effects. You just expose existing libraries or create your own APIs for doing side effects. When these effects are attached to the application they will be tracked by the devtools giving you additional debugging information. By "injecting" the effects this way also opens up for easier testability of your logic.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Modules
22

33
```marksy
4-
<Example name="api/modules" view />
4+
h(Example, { name: "api/modules", view: true })
55
```
66

77
When you have multiple application configurations, each with their own state, effects etc. you can give them a namespace by simply importing the modules and attach them to the **modules** config property.

0 commit comments

Comments
 (0)