Logic
Once you have initialised a logic with const logic = kea({})
, there are a few things you can do with it:
#
PropertiesThere are several properties you may access on a logic.
#
logic.actionCreatorsAn array of functions that create a Redux action.
Defaults to {}
#
logic.actionKeysAn object that returns the local short form for a Redux action's type
if present:
Defaults to {}
#
logic.actionsAction creators that are wrapped with Redux's dispatch
.
Defaults to {}
#
logic.cacheAn object you can use to store random data on that's accessible from all parts of the logic.
This is not meant to pass data around, but to help plugins manage their work.
Defaults to {}
#
logic.connectionsAll the other logic this logic
depends on, which is mounted with this logic. Includes itself.
Defaults to {}
#
logic.constantsConstants object that is created from an array.
Defaults to {}
#
logic.defaultsDefault values as they were when the logic was created.
Defaults to {}
#
logic.eventsVarious lifecycle events for the logic. You should not access this directly.
Defaults to {}
#
logic.listenersArray of functions listening for certain events. You should not access logic.listeners
directly,
but dispatch actions
that the listeners then listen to!
Defaults to undefined
#
logic.propTypesOptional PropTypes given to the logic.
Defaults to {}
#
logic.reducerThe combined redux-style reducer for this logic:
Defaults to undefined
#
logic.reducerOptionsOptions that were used when creating this logic's reducers
Defaults to {}
#
logic.reducersRedux-style reducers for this logic:
Defaults to {}
#
logic.selectorSelector to find the logic's reducer in the store
Defaults to undefined
#
logic.selectorsSelectors to find each individual reducer or other selector in the store
Defaults to {}
#
logic.sharedListenersObject to help share code between listeners
Defaults to undefined
#
logic.valuesConvenient shorthand for accessing selectors. Uses getters under the hood.
Defaults to {}
#
Methods#
logic()By calling just logic(something)
, we call any of the following methods:
#
logic.wrap(Component)Wrap the logic around a React Component (functional or Class) and give it access to all actions and values.
You can also use the shorthand logic(Component)
, demonstrated below:
#
logic.build(props)Build the logic, but don't yet connect it to Redux
You may also use the shorthand logic(props)
.
Builds are cached on the context, so calling it a on every render is very fast, assuming the key doesn't change.
note
logic.build
accepts a second parameter: .build(props, autoConnectInListener)
To read more on the autoConnectInListener
parameter, check out
"Calling mount()
inside listeners with autoConnect: true
"
under the "Usage without React" page.
#
logic.mount()Mount the logic on Redux, return a function that unmounts
Shorthand for logic.build().mount()
#
logic.extend(input)Add more features to the logic