Please specify the recommended order in which actions, listeners, shared listeners must be written in kea([])
karthik-hr opened this issue · comments
Can you share us recommended way of writing following inside kea([])?
- events
- afterMount
- beforeUnmount
- actions
- listeners
- sharedListeners
- reducers
- selectors
- loaders from kea-loaders
- defaults
- path
- connect
- keys
etc
kea([
afterMount(({actions}) => {
actions.init()
}),
listeners(({actions, sharedListeners}) => ({
init: async () => {
...
},
doSomething: sharedListeners.doSomething
}),
sharedListeners(() => ({
doSomething: () => {
....
}
}))
])
I encountered init inside listeners() not been called when afterMount is above listeners().
similarly sharedListeners.doSomething is undefined inside listeners() when sharedListeners() placed after listeners()
Hey @karthik-hr , usually the logic is simple: whatever is declared higher up, is accessible lower down.
That said, this list is in the order the Kea v2 -> v3 automatic codegen arranges things, and can act as a guide:
const supportedProperties = {
props: 'kea',
key: 'kea',
path: 'kea',
connect: 'kea',
actions: 'kea',
defaults: 'kea',
loaders: 'kea-loaders',
forms: 'kea-forms',
subscriptions: 'kea-subscriptions',
windowValues: 'kea-window-values',
reducers: 'kea',
selectors: 'kea',
sharedListeners: 'kea',
thunks: 'kea-thunk',
listeners: 'kea',
start: ['kea-saga', 'saga'],
stop: ['kea-saga', 'cancelled'],
saga: 'kea-saga',
workers: 'kea-saga',
takeEvery: 'kea-saga',
takeLatest: 'kea-saga',
actionToUrl: 'kea-router',
urlToAction: 'kea-router',
events: 'kea',
}