-
Notifications
You must be signed in to change notification settings - Fork 595
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
update view API to be (state, prev, send) #35
Comments
👍 to reordering the params. Would it make sense to put |
context for anyone like me who wasn't aware. @yoshuawuyts to be honest i'm not quite sold on |
or i'm being silly, a similar project |
// view(context, send)
const view = ({ params, state, oldState }, send) => choo.view`
<main>${params.foo} and ${state.bar}</main>
` 🙏 |
const view = (state, send) => choo.view`
<main>${state.params.foo} and ${state.bar}</main>
` |
@kristoferjoseph but where would the const html = require('choo/html')
const view = (state, prev, send) => html`
<main>${state.params.foo} and ${state.bar}</main>
` We could maybe get super smart and do a const mainView = (state, send) => html`
<main>${state.params.foo} and ${state.bar}</main>
`
const diffView = (state, prev, send) => html`
<div>${prev.foo} become ${state.foo}</div>
` This would have the downside that omitting // prev.foo is undefined
const diffView = (state, prev) => html`
<div>${prev.foo} become ${state.foo}</div>
` @contra while in ES6 that API looks quite good, it's not that great when not on board of the babel train. I personally only use a tiny subset of ES5 / ES6 and would rather not rely on object destructuring for this particular API |
@yoshuawuyts OK I can get behind passing |
@kristoferjoseph haha, yeah that's the idea - but you reckon we should do the |
@yoshuawuyts Regarding the |
@timwis yeah, you're totally right - mentally I've been geared to have data go first and any type of callback last, so we should probs just do |
I am not a fan of using the magical |
Just to be clear, with this new API |
@contra very good point; it def should be - so yes. edit: Do you think that's acceptable? If you've got any reservations I'd def be keen to hear them; want to get this API right hey ✨ edit2: The validation call could be done through |
@yoshuawuyts How would that work with non-object states? (#23) Not against it, but it might add some extra complexity to save one function param (or destructure). |
|
So state would always be an object; #23 refers to having non-objects as keys on the state; e.g. being able to do: app.model({
namespace: foo,
state: [ 'bin', 'bar', 'baz' ]
})
// yields state of: { foo: [ 'bin', 'bar', 'baz' ], params: {} } The implication of #23 is, however, that non-namespaced state must always be an object that can be merged with the existing state. I think the overhead of having As per #82 |
@yoshuawuyts Ah sorry, misunderstood where you wanted that to go. LGTM 💯 |
Closing as 3.0 is imminent; wanna make sure all issues are taken care of. Releasing soooon™ ✨ |
Since
v2.1.4
(oops, semver) we're now also passing theoldState
down to views. Theview
api now looks like:Instead I reckon it might be nicer to have:
This would definitely be a breaking change, but actually not that hard to fix (e.g. we can provide a regex heyyyy). What do people think?
The text was updated successfully, but these errors were encountered: