-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v5] Actor status object #4199
[v5] Actor status object #4199
Changes from all commits
aabb79e
0c2e562
31a24c5
620f158
5563f27
2f9d497
4884de5
4f35de4
27806d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,18 @@ | |
EventObject, | ||
Subscription, | ||
AnyActorSystem, | ||
ActorRefFrom | ||
ActorRefFrom, | ||
ActorStatusObject, | ||
TODO | ||
} from '../types'; | ||
|
||
export interface ObservableInternalState<T, TInput = unknown> { | ||
export type ObservableInternalState< | ||
T, | ||
TInput = unknown | ||
> = ActorStatusObject<T> & { | ||
subscription: Subscription | undefined; | ||
status: 'active' | 'done' | 'error' | 'canceled'; | ||
data: T | undefined; | ||
input: TInput | undefined; | ||
} | ||
}; | ||
|
||
export type ObservablePersistedState<T, TInput = unknown> = Omit< | ||
ObservableInternalState<T, TInput>, | ||
|
@@ -47,7 +50,7 @@ | |
|
||
return { | ||
config: observableCreator, | ||
transition: (state, event, { self, id, defer }) => { | ||
Check failure on line 53 in packages/core/src/actors/observable.ts GitHub Actions / build
|
||
if (state.status !== 'active') { | ||
return state; | ||
} | ||
|
@@ -64,14 +67,15 @@ | |
}); | ||
return { | ||
...state, | ||
data: (event as any).data | ||
output: (event as any).data | ||
}; | ||
case errorEventType: | ||
return { | ||
...state, | ||
status: 'error', | ||
error: (event as any).data, | ||
input: undefined, | ||
data: (event as any).data, // TODO: if we keep this as `data` we should reflect this in the type | ||
output: (event as any).data, // TODO: if we keep this as `data` we should reflect this in the type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after the change we'll be able to drop this comment |
||
subscription: undefined | ||
}; | ||
case completeEventType: | ||
|
@@ -97,8 +101,9 @@ | |
return { | ||
subscription: undefined, | ||
status: 'active', | ||
data: undefined, | ||
input | ||
output: undefined, | ||
input, | ||
error: undefined | ||
}; | ||
}, | ||
start: (state, { self, system }) => { | ||
|
@@ -122,14 +127,10 @@ | |
} | ||
}); | ||
}, | ||
getSnapshot: (state) => state.data, | ||
getPersistedState: ({ status, data, input }) => ({ | ||
status, | ||
data, | ||
input | ||
}), | ||
getSnapshot: (state) => state.output, | ||
getPersistedState: (state) => state, | ||
getStatus: (state) => state, | ||
restoreState: (state) => ({ | ||
Check failure on line 133 in packages/core/src/actors/observable.ts GitHub Actions / build
|
||
...state, | ||
subscription: undefined | ||
}) | ||
|
@@ -161,7 +162,7 @@ | |
// TODO: event types | ||
return { | ||
config: lazyObservable, | ||
transition: (state, event) => { | ||
Check failure on line 165 in packages/core/src/actors/observable.ts GitHub Actions / build
|
||
if (state.status !== 'active') { | ||
return state; | ||
} | ||
|
@@ -172,7 +173,7 @@ | |
...state, | ||
status: 'error', | ||
input: undefined, | ||
data: (event as any).data, // TODO: if we keep this as `data` we should reflect this in the type | ||
error: (event as any).data, // TODO: if we keep this as `data` we should reflect this in the type | ||
subscription: undefined | ||
}; | ||
case completeEventType: | ||
|
@@ -194,11 +195,11 @@ | |
return state; | ||
} | ||
}, | ||
getInitialState: (_, input) => { | ||
Check failure on line 198 in packages/core/src/actors/observable.ts GitHub Actions / build
|
||
return { | ||
subscription: undefined, | ||
status: 'active', | ||
data: undefined, | ||
output: undefined, | ||
input | ||
}; | ||
}, | ||
|
@@ -225,15 +226,12 @@ | |
}); | ||
}, | ||
getSnapshot: (_) => undefined, | ||
getPersistedState: ({ status, data, input }) => ({ | ||
status, | ||
data, | ||
input | ||
}), | ||
getPersistedState: (state) => state, | ||
getStatus: (state) => state, | ||
restoreState: (state) => ({ | ||
...state, | ||
subscription: undefined | ||
}) | ||
restoreState: (state) => | ||
({ | ||
...state, | ||
subscription: undefined | ||
} as TODO) | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this is a mistake -
nextEventType
shouldn't assign tooutput
. I'm working on this branch locally so I'll fix this.