Giter Site home page Giter Site logo

Comments (5)

cloud-walker avatar cloud-walker commented on May 19, 2024 2

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.

drcmda avatar drcmda commented on May 19, 2024

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.

divmain avatar divmain commented on May 19, 2024

@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.

divmain avatar divmain commented on May 19, 2024

@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.

bingomanatee avatar bingomanatee commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.