connected components don't work with dynamic logic
See original GitHub issueThanks for this project, it works great, definitely a great help and less boilerplate for redux.
I’m trying to use the connect feature of kea and come up with the following issues:
-
connect only seems to work if a path is defined, otherwise kea creates a new namespace for the second component. This could be improved in the documentation.
-
connect doesn’t work if the logic has a
key
setting, it gives the following error:
[KEA-LOGIC] selector "value" missing for logic: function response(Klass) {
...
Is there a way to use connect with a dynamic component?
Here is an example code I’m using (in react native):
const keaItem = {
// path: () => ['scenes', 'item'], (1)
// key: props => props.name, (2)
// path: key => ['scenes', 'item', key], (2)
actions: () => ({
toggle: true,
}),
reducers: ({ actions, key, props }) => ({
value: [
false,
PropTypes.bool,
{
[actions.toggle]: (state, payload) => {
return !state
},
},
],
}),
}
const itemLogic = kea(keaItem)
export class Item extends React.Component {
render() {
return (
<View>
<Title>Item</Title>
<Text>Value: {this.props.value ? 'true' : 'false'}</Text>
<Button onPress={this.actions.toggle}>
<Text>Toggle</Text>
</Button>
</View>
)
}
}
const ConnectedItem = kea(keaItem)(Item)
export class Other extends React.Component {
render() {
return (
<View>
<Title>Other</Title>
<Text>Value: {this.props.value ? 'true' : 'false'}</Text>
</View>
)
}
}
const keaOther = {
connect: {
props: [itemLogic, ['value']],
},
}
const ConnectedOther = kea(keaOther)(Other)
export default class Container extends React.Component {
render() {
return (
<View>
<Title>Container</Title>
<ConnectedItem name="demo" />
<ConnectedOther name="demo" />
</View>
)
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
logic - Z3 connected components - Stack Overflow
As part of a puzzle solver, I dynamically build a graph, nodes and edges, from user input. Each node is assigned an integer...
Read more >Connected Components in an Undirected Graph
Finding connected components for an undirected graph is an easier task. ... If v is not visited before, call the DFS. and print...
Read more >Dynamic logic (digital electronics) - Wikipedia
In integrated circuit design, dynamic logic (or sometimes clocked logic) is a design methodology in combinatory logic circuits, particularly those ...
Read more >A Study of Connectivity on Dynamic Graphs: Computing ...
This work focuses on connectivity in a dynamic graph. ... The logical extension ... namic graphs, connected components do not partition the vertices....
Read more >First order Logic. Compactness theorem. A task with solution.
It is not clear to me if you are asking about "The set of nodes satisfying P is connected" or "there is a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I pushed out
v0.28.2
that addresses the issues mentioned above, but doesn’t solve all open issues with these dynamic connectedwithKey
logic stores.What works now, but didn’t in
0.28.1
.withKey(props => props.id)
with actions, so like this:This way the key is automatically added to the actions.
You may now add
propTypes: {}
to either@connect({})
or@kea({})
and they will be added to your component. Try it withpropTypes: { bla: PropTypes.number.isReuired }
and see the error!There was a conflict with actions and multiple instances of a dynamic logic store (with a different key). Only the first version got cached and all actions used the same key. This is fixed.
The issues that are still out there:
When connecting to a
withKey
logic store, you can only selectreducers
. Everything that was inselectors
will be invisible.The logic store that contains the data needs to be wrapped around a component. You can’t just create it and then only
@connect
to it from other logic stores. It has to wrap a React component.I still need to write tests.
All help with testing, reporting bugs, writing documentation, etc is much appreciated! 😃
Kea 1.0 addresses many of these issues. See here for an example of connecting to dynamic logic with props: https://kea.js.org/api/kea
I’m closing this issue now. Feel free to comment/reopen or make a new issue if there are problems/questions with the new implementation.