Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mixed-mode] [idea] More composability. #19

Open
trusktr opened this issue Aug 6, 2015 · 4 comments
Open

[mixed-mode] [idea] More composability. #19

trusktr opened this issue Aug 6, 2015 · 4 comments

Comments

@trusktr
Copy link

trusktr commented Aug 6, 2015

Alright, so I've adopted react-famous into my latest project (finally!). It's working great out of the box composing things like Scene, Node, and DOMElement together (using those components directly).

But now what I'm trying to do is get more organized, so I've got something like this:

    React.render(
        <Scene style={{width: '100%', height: '100%'}}>
            <FeatureMapView boardId={board._id}>
                {_.map(cards, card =>
                   <Card context={card} />
                )}
            </FeatureMapView>
        </Scene>,
        this.$('.board-container')[0]
    )

where FeatureMapView extends Node,

import Node             from 'react-famous/Node'

class FeatureMapView extends Node {
    ...
}

and the Card component contains a Node and DOMElement instead of extending any of them:

class Card extends React.Component {

    render() {
        let card = this.props.context
        return (
            <Node>
                <DOMElement>
                    <BlazeCardWrapper context={card} />
                </DOMElement>
            </Node>
        )
    }
}

. The BlazeCardWrapper component just renders some normal HTML in the DOMElement.

The problem is, now that I've wrapped Node and DOMElement inside of my Card class, they don't become part of the scene graph as I was hoping. I was hoping to have the following hierarchy:

Scene
  FeatureMapView // (extends Node)
    Node // wrapped by Card, has DOMElement content

react-famous says

Error: Missing famous scene.

It would be great if we could allow for things to be wrapped/owned by other components in order to have more control of the scene graph composition.

Any ideas @pilwon?

@trusktr trusktr changed the title [idea] Better composability. [idea] More composability. Aug 6, 2015
@trusktr
Copy link
Author

trusktr commented Aug 6, 2015

Aha, I found the immediate solution for my case, I just pass the _famousParent:

class Card extends React.Component {

    render() {
        let card = this.props.context
        return (
            <Node _famousParent={this.props._famousParent}> // <-- right here.
                <DOMElement>
                    <BlazeCardWrapper context={card} />
                </DOMElement>
            </Node>
        )
    }
}

@trusktr
Copy link
Author

trusktr commented Aug 6, 2015

Maybe we can add some additional logic somewhere to do this automatically?

@trusktr
Copy link
Author

trusktr commented Aug 6, 2015

If there is no immediate _famousParent, we can search up the tree for one.

I think that's what FamousUtil.getFamousParent(this) is supposed to do? If so, maybe I found a bug?

@paynecodes
Copy link

Any ideas here @pilwon?

@trusktr trusktr changed the title [idea] More composability. [mixed-mode] [idea] More composability. Sep 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants