keajs / kea

Batteries Included State Management for React

Home Page:https://keajs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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([])?

  1. events
  2. afterMount
  3. beforeUnmount
  4. actions
  5. listeners
  6. sharedListeners
  7. reducers
  8. selectors
  9. loaders from kea-loaders
  10. defaults
  11. path
  12. connect
  13. 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',
}