Logic
Once you have initialised a logic with const logic = kea({}), there are a few things you can do with it:
Properties#
There are several properties you may access on a logic.
logic.actionCreators#
An array of functions that create a Redux action.
Defaults to {}
logic.actionKeys#
An object that returns the local short form for a Redux action's type if present:
Defaults to {}
logic.actions#
Action creators that are wrapped with Redux's dispatch.
Defaults to {}
logic.cache#
An 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.connections#
All the other logic this logic depends on, which is mounted with this logic. Includes itself.
Defaults to {}
logic.constants#
Constants object that is created from an array.
Defaults to {}
logic.defaults#
Default values as they were when the logic was created.
Defaults to {}
logic.events#
Various lifecycle events for the logic. You should not access this directly.
Defaults to {}
logic.listeners#
Array 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.propTypes#
Optional PropTypes given to the logic.
Defaults to {}
logic.reducer#
The combined redux-style reducer for this logic:
Defaults to undefined
logic.reducerOptions#
Options that were used when creating this logic's reducers
Defaults to {}
logic.reducers#
Redux-style reducers for this logic:
Defaults to {}
logic.selector#
Selector to find the logic's reducer in the store
Defaults to undefined
logic.selectors#
Selectors to find each individual reducer or other selector in the store
Defaults to {}
logic.sharedListeners#
Object to help share code between listeners
Defaults to undefined
logic.values#
Convenient 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