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

Pass root in second argument to app(). #410

Closed
jorgebucaran opened this issue Oct 8, 2017 · 15 comments
Closed

Pass root in second argument to app(). #410

jorgebucaran opened this issue Oct 8, 2017 · 15 comments

Comments

@jorgebucaran
Copy link
Owner

jorgebucaran commented Oct 8, 2017

The proposal is to remove the app's root property and do the same passing it in the second argument to app().

Before

app({  init, view, state, actions, root }) 

After

app({ init, view, state, actions }, root) 

e.g.

app(
  { 
    init, 
    view, 
    state, 
    actions 
  }, 
  document.getElementById("app")
)

Pros

  • Make app() props have to deal only with the state management side of things.
  • Other libraries often do the same, e.g., P/React's render(elm, root), Elm's Elm.Main.embed(root), mithril's m,mount(document.body, Counter) (the order is reversed here though), Vue's $mount, etc.
  • Cuts like 10 bytes. 😅

Cons

  • There is nothing wrong with the current way of doing things.
  • Adds like 10 bytes.
  • Complicates the signature of HOAs. Thanks @okwolf.
@okwolf
Copy link
Contributor

okwolf commented Oct 8, 2017

@jorgebucaran how would this work with HOAs? Would they need to accept multiple args as well, and call the app function with both the props and root?

@jorgebucaran
Copy link
Owner Author

@okwolf Oh, I didn't think about it. I am starting to dislike this proposal haha.

@pspeter3
Copy link
Contributor

pspeter3 commented Oct 8, 2017

You could possibly separate the app factory and the render factory.

@SkaterDad
Copy link
Contributor

SkaterDad commented Oct 8, 2017 via email

@lukejacksonn
Copy link
Contributor

I don't expect many people will actually include a root prop that often anyway, but instead let it fallback to default (document.body). I like the idea but the cons seem to outweigh the pros.

@jorgebucaran jorgebucaran added the wontfix Forget it, sorry label Oct 10, 2017
@jorgebucaran
Copy link
Owner Author

jorgebucaran commented Oct 10, 2017

Thanks everyone! I'll keep things the way they are. 👍

@jorgebucaran jorgebucaran removed the wontfix Forget it, sorry label Oct 10, 2017
@SkaterDad
Copy link
Contributor

Out of curiosity, what's the benefit of this change? I can't access Slack from work to read the conversation.

@jorgebucaran
Copy link
Owner Author

Now, with HOA builtin support pushed to userland, we can revive this and as per discussion on Slack. Shall we implement it?

@pspeter3
Copy link
Contributor

I prefer it but I do think we should have principles for why to answer @SkaterDad

@jorgebucaran
Copy link
Owner Author

The real (not really) question is, how do we feel about formatters like prettier making the code this:

app(
  { 
    init, 
    view, 
    state, 
    actions 
  }, 
  document.getElementById("app")
)

@jorgebucaran
Copy link
Owner Author

@SkaterDad The convo was basically that since builtin HOA support is out, and:

Complicates the signature of HOAs. Thanks @okwolf.

...was one of the reasons to turn this down, we can implement it now. Preact/React/Inferno users trying Hyperapp will feel at home and we can save some bytes too.

@pspeter3
Copy link
Contributor

I still want to make sure we have consistent reasoning for API changes. As we approach 1.0, the API will become locked.

@jorgebucaran
Copy link
Owner Author

Well, let's approach it this way. What's not to like about

app(props, container)
app(
  { 
    init, 
    view, 
    state, 
    actions 
  }, 
  document.getElementById("app")
)
app({ init, view, state, actions }, document.getElementById("app"))

@okwolf
Copy link
Contributor

okwolf commented Oct 14, 2017

@jorgebucaran FYI using this also breaks your compose function.

@jorgebucaran
Copy link
Owner Author

@okwolf Thanks, I'll update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants