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
Boilerplate reduction for v0.8.0 #56
Comments
Wow, I really like your suggestion. Thanks! I hear you about boilerplate problems, and I'd like to reduce it as much as possible (but avoiding an API that makes the framework feel too "magical").
That's a very important problem to solve.
Yes they are. I need to give some thought to your implementation, and also to the overall API design. My intuition is to lean towards your suggestion, since JS is after all a dynamically typed language, where we are used to code without specifying types or contracts. Interfaces in Cycle are a bit against that. I'll toy around with this suggestion, and comment back here soonish. 👍 |
Commits f9e733a and a52db82 are implementing this. Boilerplate is being succesfully removed. 👍 The README example would be: var HelloModel = Cycle.createModel(function (intent) {
return {name$: intent.get('changeName$').startWith('')};
});
var HelloView = Cycle.createView(function (model) {
return {
vtree$: model.get('name$')
.map(function (name) {
return h('div', {}, [
h('label', 'Name:'),
h('input', {
'attributes': {'type': 'text'},
'ev-input': 'inputText$'
}),
h('hr'),
h('h1', 'Hello ' + name)
]);
})
};
});
var HelloIntent = Cycle.createIntent(function (view) {
return {
changeName$: view.get('inputText$')
.map(function (ev) { return ev.target.value; })
};
});
Cycle.circularInject(HelloModel, HelloView, HelloIntent);
Cycle.createRenderer('.js-container').inject(HelloView); I'll still do some commits on Thanks @dobrite ! |
And I've been investigating if I could use ES6 Proxy or something equivalent (maybe a polyfill), but there are no hopes yet. We need to wait for ES6 implemented in browsers. Only then can we make another version of Cycle without the use of |
Wow, absolutely amazing! I looked through the 2 commits and what I saw looked good (but I'll admit most of it was over my head). I'll pull the branch and try it out with my toy app and see how it goes. So excited to delete those arrays. 🍻 I too looked for polyfills, googled, and checked SO and nothing turned up. It would be lovely to remove the gets eventually, but that will likely take a long while. |
Toy app working! 👍 |
So my app hits a brick wall after a few minutes of running (~1.5 gb of ram allocated).
Perhaps this? No idea what it is but it looked a little 🐟 on my read through. |
Would ES5 getters/setters further clean up the syntax? Or is that still too much to expect from the supported browsers? |
Oh never mind, I guess you'd still have to know the props up-front to define getters/setters. |
I'll try to fix it before merging to master. Can you share the code, or tell me the use case, so I can reproduce it?
Yeah I looked into that, and it won't be enough. Has to be ES6 Proxy. |
The |
Commit aad0dee removes Intent.inject(View).inject(Model).inject(Intent);
|
Memory leak looks good on my end! 👍 I think the change to remove |
Merged to master and considered done. |
Related to #40
If a proxy is used between the injected model/view/intent then there is no need to declare an interface upfront. The flip side is that the observables hanging off the model/view/intent must be accessed through a getter function and a stringed arg.
Example from the README:
Modified
data-flow-node.js
:ES6 Proxy would be perfect for this, but they are very much a WIP.
One idea is to default to
loose
mode (as above) with an opt in tostrict mode
(as it is now) by passing in interface string arrays. This opt-int strict checking is how React handles it with their propTypes. I found myself constantly making errors during the writing and refactoring of a toy cycle app.I'm somewhat on the fence with the need for the
.get
(it is ugly in it's own way) and the stringed stream arg, but those massive interface arrays in the TodoMVC are scary. It would be awesome to couple this with the removal of theevents
view property as outlined in #40. That would make the README example app really nice and welcoming:I'm probably missing something obvious here that is a deal-breaker. Also, the explicit interface declaration was likely a purposeful design decision. In that case please feel free to ignore my suggestion!
🍻
The text was updated successfully, but these errors were encountered: