Skip to content

Commit 7d7177c

Browse files
chore(merge): fix merge conflict
2 parents bc848b4 + 9f3c6f5 commit 7d7177c

File tree

7 files changed

+243
-17
lines changed

7 files changed

+243
-17
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [christianalfoni]

packages/node_modules/overmind-devtools/src/main.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,26 @@ function createWindow() {
168168
)
169169

170170
startDevtoolBackend().then(openDevtools)
171+
172+
/*
173+
BUG FIX: https://github.com/electron/electron/issues/13008#issuecomment-575909942
174+
*/
175+
let redirectURL = 'data:application/x-javascript;base64,UHJvZHVjdFJlZ2lzdHJ5SW1wbC5SZWdpc3RyeT1jbGFzc3tjb25zdHJ1Y3Rvcigpe31uYW1lRm9yVXJsKHIpe3JldHVybiBudWxsfWVudHJ5Rm9yVXJsKHIpe3JldHVybiBudWxsfXR5cGVGb3JVcmwocil7cmV0dXJuIG51bGx9fSxQcm9kdWN0UmVnaXN0cnlJbXBsLl9oYXNoRm9yRG9tYWluPWZ1bmN0aW9uKHIpe3JldHVybiIifSxQcm9kdWN0UmVnaXN0cnlJbXBsLnJlZ2lzdGVyPWZ1bmN0aW9uKHIsdCl7UHJvZHVjdFJlZ2lzdHJ5SW1wbC5fcHJvZHVjdHNCeURvbWFpbkhhc2g9bmV3IE1hcH0sUHJvZHVjdFJlZ2lzdHJ5SW1wbC5fcHJvZHVjdHNCeURvbWFpbkhhc2g9bmV3IE1hcCxQcm9kdWN0UmVnaXN0cnlJbXBsLnJlZ2lzdGVyKFtdLFtdKSxQcm9kdWN0UmVnaXN0cnlJbXBsLnNoYTE9ZnVuY3Rpb24ocil7cmV0dXJuIiJ9Ow==';
176+
electron.session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
177+
if ((/^devtools:\/\/devtools\/remote\/serve_file\/@[0-9a-f]{40}\/product_registry_impl\/product_registry_impl_module.js$/ui).test(details.url)) {
178+
// eslint-disable-next-line
179+
callback({
180+
redirectURL
181+
});
182+
return;
183+
}
184+
// eslint-disable-next-line
185+
callback({});
186+
});
171187
}
172188

173189
// This method will be called when Electron has finished
174190
// initialization and is ready to create browser windows.
175191
// Some APIs can only be used after this event occurs.
176192
app.on('ready', createWindow)
193+

packages/node_modules/overmind/src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export { MODE_DEFAULT, MODE_TEST, MODE_SSR } from './utils'
7070

7171
export { SERIALIZE, rehydrate } from './rehydrate'
7272

73+
export { Statemachine, statemachine } from './statemachine'
74+
7375
/** This type can be overwriten by app developers if they want to avoid
7476
* typing and then they can import `Action`, `Operation` etc. directly from
7577
* overmind.
@@ -239,6 +241,12 @@ export class Overmind<ThisConfig extends IConfiguration>
239241
this.eventHub = eventHub as EventEmitter<Events>
240242
this.mode = mode
241243

244+
245+
/*
246+
Expose the created actions
247+
*/
248+
this.actions = this.getActions(configuration.actions)
249+
242250
if (mode.mode === MODE_SSR) {
243251
return
244252
}
@@ -343,11 +351,6 @@ export class Overmind<ThisConfig extends IConfiguration>
343351
})
344352
}
345353

346-
/*
347-
Expose the created actions
348-
*/
349-
this.actions = this.getActions(configuration.actions)
350-
351354
if (mode.mode === MODE_DEFAULT && configuration.onInitialize) {
352355
const onInitialize = this.createAction(
353356
'onInitialize',

packages/node_modules/overmind/src/internalTypes.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ITrackStateTree,
66
} from 'proxy-state-tree'
77

8-
import { IAction, IOperator, IState } from './types'
8+
import { IAction, IConfiguration, IDerive, IOperator, IState } from './types'
99

1010
export type SubType<Base, Condition> = Pick<
1111
Base,
@@ -151,12 +151,10 @@ export interface Events {
151151

152152
// ============= PRIVATE TYPES FOR APP
153153

154-
type Derived = (parent: any, config: any) => any
155-
156154
export type ResolveState<State extends IState | null> = State extends undefined
157155
? {}
158156
: {
159-
[P in keyof State]: State[P] extends Derived
157+
[P in keyof State]: State[P] extends IDerive<IConfiguration, IState, any>
160158
? ReturnType<State[P]>
161159
: State[P] extends Array<any>
162160
? State[P]

packages/node_modules/overmind/src/ssr.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,12 @@ describe('Mock', () => {
4444

4545
overmind.state.foo = 'bar2'
4646

47-
expect(overmind.hydrate()).toEqual([
48-
{
49-
method: 'set',
50-
path: 'foo',
51-
args: ['bar2'],
52-
},
53-
])
47+
const mutations = overmind.hydrate()
48+
expect(mutations[0].method).toBe('set')
49+
expect(mutations[0].path).toBe('foo')
50+
expect(mutations[0].args).toEqual(['bar2'])
5451
})
55-
test.only('should rehydrate mutation', () => {
52+
test('should rehydrate mutation', () => {
5653
type State = {
5754
foo: string
5855
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import { IAction, createOvermind, createOvermindMock } from './'
2+
import { Statemachine, statemachine } from './statemachine'
3+
4+
describe('Statemachine', () => {
5+
test('should set initial state', () => {
6+
7+
type State = {
8+
machine: Statemachine<'FOO' | 'BAR'>
9+
}
10+
const state: State = {
11+
machine: statemachine<'FOO' | 'BAR'>({
12+
initial: 'FOO',
13+
states: {
14+
FOO: ['BAR'],
15+
BAR: ['FOO']
16+
}
17+
})
18+
}
19+
const config = {
20+
state,
21+
}
22+
23+
const overmind = createOvermindMock(config)
24+
25+
expect(overmind.state.machine.current).toBe('FOO')
26+
})
27+
test.only('should transition state', () => {
28+
type State = {
29+
machine: Statemachine<'FOO' | 'BAR'>
30+
}
31+
32+
const state: State = {
33+
machine: statemachine<'FOO' | 'BAR'>({
34+
initial: 'FOO',
35+
states: {
36+
FOO: ['BAR'],
37+
BAR: ['FOO']
38+
}
39+
})
40+
}
41+
const transition: Action = ({ state }) => {
42+
state.machine.BAR()
43+
}
44+
45+
const config = {
46+
state,
47+
actions: {
48+
transition
49+
}
50+
}
51+
52+
interface Action extends IAction<typeof config, void, void> {}
53+
54+
const overmind = createOvermindMock(config)
55+
overmind.actions.transition()
56+
expect(overmind.state.machine.current).toBe('BAR')
57+
})
58+
test('should ignore transition to invalid state', () => {
59+
60+
type State = {
61+
machine: Statemachine<'FOO' | 'BAR'>
62+
}
63+
64+
const state: State = {
65+
machine: statemachine<'FOO' | 'BAR'>({
66+
initial: 'FOO',
67+
states: {
68+
FOO: [],
69+
BAR: ['FOO']
70+
}
71+
})
72+
}
73+
const transition: Action = ({ state }) => {
74+
state.machine.BAR()
75+
}
76+
77+
const config = {
78+
state,
79+
actions: {
80+
transition
81+
}
82+
}
83+
84+
interface Action extends IAction<typeof config, void, void> {}
85+
86+
const overmind = createOvermindMock(config)
87+
overmind.actions.transition()
88+
expect(overmind.state.machine.current).toBe('FOO')
89+
})
90+
test('should run entry and exit transition', () => {
91+
expect.assertions(3)
92+
type State = {
93+
machine: Statemachine<'FOO' | 'BAR'>
94+
}
95+
96+
const state: State = {
97+
machine: statemachine<'FOO' | 'BAR'>({
98+
initial: 'FOO',
99+
states: {
100+
FOO: ['BAR'],
101+
BAR: ['FOO']
102+
}
103+
})
104+
}
105+
const transition: Action = ({ state }) => {
106+
state.machine.BAR(() => {
107+
expect(state.machine.current).toBe('BAR')
108+
state.machine.FOO()
109+
}, () => {
110+
expect(state.machine.current).toBe('BAR')
111+
})
112+
}
113+
114+
const config = {
115+
state,
116+
actions: {
117+
transition
118+
}
119+
}
120+
121+
interface Action extends IAction<typeof config, void, void> {}
122+
123+
const overmind = createOvermindMock(config)
124+
overmind.actions.transition()
125+
expect(overmind.state.machine.current).toBe('FOO')
126+
})
127+
test('should flush changes to transitions', () => {
128+
expect.assertions(1)
129+
130+
type State = {
131+
machine: Statemachine<'FOO' | 'BAR'>
132+
}
133+
134+
const state: State = {
135+
machine: statemachine<'FOO' | 'BAR'>({
136+
initial: 'FOO',
137+
states: {
138+
FOO: ['BAR'],
139+
BAR: ['FOO']
140+
}
141+
})
142+
}
143+
const transition: Action = ({ state }) => {
144+
state.machine.BAR()
145+
}
146+
147+
const config = {
148+
state,
149+
actions: {
150+
transition
151+
}
152+
}
153+
154+
interface Action extends IAction<typeof config, void, void> {}
155+
156+
const overmind = createOvermind(config)
157+
overmind.reaction((state) => state.machine.current, (value) => {
158+
expect(value).toBe('BAR')
159+
})
160+
overmind.actions.transition()
161+
})
162+
})
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Derive } from './'
2+
3+
export type StatemachineDefinition<States extends string> = {
4+
initial: States,
5+
states: {
6+
[State in States]: Array<States>
7+
}
8+
}
9+
10+
export type Statemachine<States extends string> = {
11+
current: States
12+
reset: () => void
13+
} & {
14+
[State in States]: <T>(entry?: () => T, exit?: () => void) => T
15+
}
16+
17+
class Machine<States extends string> {
18+
current: States
19+
private _currentExit: (() => void) | undefined
20+
constructor(definition: StatemachineDefinition<States>) {
21+
this.current = definition.initial
22+
23+
Object.keys(definition.states).reduce((aggr, key) => {
24+
aggr[key] = (entry, exit) => {
25+
if (definition.states[this.current].includes(key as any)) {
26+
if (this._currentExit) this._currentExit()
27+
this._currentExit = exit
28+
this.current = key as any
29+
return entry && entry()
30+
}
31+
}
32+
33+
return aggr
34+
}, this)
35+
}
36+
reset() {
37+
if (this._currentExit) {
38+
this._currentExit()
39+
this._currentExit = undefined
40+
}
41+
}
42+
}
43+
44+
export function statemachine<States extends string>(definition: StatemachineDefinition<States>): Statemachine<States> {
45+
return new Machine(definition) as any
46+
}

0 commit comments

Comments
 (0)