Skip to content

Commit 2ea2847

Browse files
committed
✏️ clean up generated types
1 parent e2270ff commit 2ea2847

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

packages/core/src/index.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export interface IActionNode<State, Props> extends IWithNodeState {
6969
id: string
7070
name: string
7171
type: NodeType.Action
72-
fn: (state: Draft<State>, props: Props) => void | Promise<void>
72+
fn: (state: State, props: Props) => void | Promise<void>
7373
parent?: IAnyNode<State, Props>
7474
}
7575
export interface IStateNode<State, Props> extends IWithNodeState {
@@ -92,19 +92,19 @@ export interface ISequenceNode<State, Props> extends IWithNodeState {
9292
id: string
9393
type: NodeType.Sequence
9494
parent?: IAnyNode<State, Props>
95-
children: Array<ICompositeNode<State, Props> | ILeafNode<State, Props>>
95+
children: IAnyChildNode<State, Props>[]
9696
}
9797
export interface IParallelNode<State, Props> extends IWithNodeState {
9898
id: string
9999
type: NodeType.Parallel
100100
parent?: IAnyNode<State, Props>
101-
children: Array<ICompositeNode<State, Props> | IActionNode<State, Props>>
101+
children: IAnyChildNode<State, Props>[]
102102
}
103103
export interface ISelectorNode<State, Props> extends IWithNodeState {
104104
id: string
105105
type: NodeType.Selector
106106
parent?: IAnyNode<State, Props>
107-
children: Array<ICompositeNode<State, Props> | IActionNode<State, Props>>
107+
children: IAnyChildNode<State, Props>[]
108108
}
109109
export interface IDecoratorNode<State, Props> extends IWithNodeState {
110110
id: string
@@ -147,7 +147,6 @@ export interface IWithNodeState {
147147
*/
148148
setValue: (key: string, value: any) => any
149149
}
150-
151150
export type IOptions<Props> = {
152151
props?: Props
153152
setState: any
@@ -226,7 +225,7 @@ export const nodes = {
226225
* Runs child nodes in sequence until it finds one that succeeds. Succeeds when it finds the first child that succeeds. For child nodes that fail, it moves forward to the next child node. While a child is running it stays on that child node without moving forward.
227226
*/
228227
selector: function<State, Props>(
229-
children: Array<ICompositeNode<State, Props> | IActionNode<State, Props>>
228+
children: IAnyChildNode<State, Props>[]
230229
): ISelectorNode<State, Props> {
231230
return {
232231
id: nanoid(),
@@ -239,7 +238,7 @@ export const nodes = {
239238
* Runs each child node one by one. Fails for the first child node that fails. Moves to the next child when the current running child succeeds. Stays on the current child node while it returns running. Succeeds when all child nodes have succeeded.
240239
*/
241240
sequence: function<State, Props>(
242-
children: Array<ICompositeNode<State, Props> | ILeafNode<State, Props>>
241+
children: IAnyChildNode<State, Props>[]
243242
): ISequenceNode<State, Props> {
244243
return {
245244
id: nanoid(),
@@ -254,7 +253,7 @@ export const nodes = {
254253
* Runs all child nodes in parallel. Continues to run until a required number of child nodes have either failed or succeeded.
255254
*/
256255
parallel: function<State, Props>(
257-
children: Array<ICompositeNode<State, Props> | IActionNode<State, Props>>
256+
children: IAnyChildNode<State, Props>[]
258257
): IParallelNode<State, Props> {
259258
return {
260259
id: nanoid(),
@@ -265,7 +264,7 @@ export const nodes = {
265264
},
266265
condition: function<State, Props>(
267266
name: string,
268-
fn?: (state: State, props: Props) => void
267+
fn?: (state: State, props: Props) => any
269268
): IConditionNode<State, Props> {
270269
return {
271270
id: nanoid(),
@@ -327,7 +326,7 @@ export const nodes = {
327326
},
328327
action: function<State, Props>(
329328
name: string,
330-
fn: (state: Draft<State>, props: Props) => void
329+
fn: (state: State, props: Props) => void
331330
): IActionNode<State, Props> {
332331
return {
333332
id: nanoid(),
@@ -432,7 +431,7 @@ function _interpret<State, Props>(
432431

433432
const nextState = produce(
434433
state,
435-
draft => node.fn(draft, options.props || ({} as Props)),
434+
draft => node.fn(draft as State, options.props || ({} as Props)),
436435
patches => {
437436
node.setValue(_StoreKey.Patches, patches)
438437

packages/react/example/behaviors/DragBehavior.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import {nodes} from '@btree/core'
22

3-
type TreeProps = {
3+
type Props = {
44
targetEvent?: React.MouseEvent<HTMLDivElement, MouseEvent>
55
containerEvent?: MouseEvent
66
}
77

8-
type TreeState = {
8+
type State = {
99
isDragging: boolean
1010
x: number
1111
y: number
1212
dx: number
1313
dy: number
1414
}
1515

16-
const DragBehavior = nodes.root<TreeState, TreeProps>('DragBehavior', () =>
16+
const DragBehavior = nodes.root<State, Props>('DragBehavior', () =>
1717
nodes.selector([
1818
nodes.sequence([
1919
nodes.condition('Is dragging', (state, props) => {

0 commit comments

Comments
 (0)