Comments (5)
Why not just use something like mapProps
from recompose
?
import React from 'react'
import {compose} from 'ramda'
import {injectState} from 'freactal'
import {mapProps} from 'recompose'
const enhance = compose(
injectState,
mapProps(props => ({
value: props.state.counter,
onClick: props.effects.addOne,
})),
)
const CounterDisplay = ({value, onClick}) => (
<div>
<h2>Current counter value is: {value}</h2>
<button onClick={onClick}>Add one</button>
</div>
)
export default enhance(CounterDisplay)
from freactal.
Hope this is getting in there as well!
For reference: https://www.reddit.com/r/reactjs/comments/68uqvb/freactal_deadsimple_composable_state_management/dh3ao4v/?context=3
That should be totally doable, but it there's no built-in solution for that right now. Would you mind opening an issue? I should have some time later in the week to address this and provide a baked-in solution.
from freactal.
@drcmda, to clarify, does using shouldComponentUpdate
and returning this.props.item !=== nextProps.item
. This places the burden on React rather than freactal, but the performance characteristics should be the same (I think). No matter what, you're going to be doing a lot of checks to see if the thing that was updated is the thing that is depended upon.
from freactal.
@alex-haproff, your issue is slightly different, and I'd like to provide a friendly interface to do what you want. You can already do that somewhat by specifying state keys to injectState
. That will inject those state keys as props, without any implicit Angular-esque magic. effects
is not spread into props
, but that's less of an issue, I think?
from freactal.
This approach is doable with vanilla components and pure view components. You can inject state into the component, and then selectively pass state and effects into properties of the pure view that you do NOT inject state into.
that pure component is then outside the Freactal awareness sphere and treats your subset of parameters like conventional redux values. You can even mix in state from the container for localized freactal-less tossaway values. You can even rename properties and effects if it benefits you at this level.
The question becomes then: for the view component do you wrap it in injectState or not?
if you do NOT, then any of ITS children are cut off from the Freactal access.
if you DO injectState, then it will have an event property, a state property, and other props that are filtered from those objects -- a gain in clarity and emphasis, but also, some redundancy.
If you are going to strive for this level of control consider using shouldComponentUpdate to limit the components' refresh. If you are so convinced that you know exactly what this component should be listening to that you are taking control of it, you might as well go to the next level of management.
from freactal.
Related Issues (20)
- state and effects
- middleware not executing in Jest
- Calculated states giving me the blues HOT 1
- A State Factory for Freactal
- Freactal doesn't work well with recursive state provider components. HOT 13
- A "Freactal Manager" module: Freactal Seed HOT 3
- effects.initialize executed version is unpatched through middleware.
- Putting up a Starter Kit with Freactal
- effects can't access parent scope
- Jumping cursor with controlled input HOT 1
- Looking for a new maintainer! HOT 15
- An alternative: looking glass engine
- Type codebase with flow HOT 3
- Any intention to support decorators? HOT 6
- effects with async/await functions HOT 4
- Published package (v2.0.0) is out of sync with the actual code? HOT 15
- (Re-)Publish Freactal intro on Hacker Noon? HOT 3
- React Native database? HOT 2
- Injecting new state asynchronously HOT 6
- middleware
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freactal.