-
Notifications
You must be signed in to change notification settings - Fork 76
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
Handle ES6 classes #89
Comments
@KidkArolis @oliverwoodings would love to hear your thoughts on this |
In v0.9 branch |
@jhollingworth could you provide an example of getting some value from a import Marty from 'marty'
import React from 'react'
export class BlockStore extends Marty.Store {
constructor(options) {
super(options)
this.state = {
1: {
data: {
some: 'data'
}
}
}
}
getData(id) {
return this.state[id].data;
}
}
export default class Block extends Marty.Component {
constructor(props, context) {
super(props, context)
this.listenTo = BlockStore
}
getState() {
return {
data: BlockStore.getData(this.props.id)
}
}
render() {
return (
<div>
Block Marty!
{JSON.stringify(this.state.data)}
</div>
)
}
} But a call to After reading #153 I have a feeling I'm missing something too. Could you hint me in the right direction? :) |
Sorry, documentation is next on my list :) We have a new top level API class BlockStore extends Marty.Store {
constructor(options) {
super(options)
this.state = {
1: {
data: {
some: 'data'
}
}
}
}
getData(id) {
return this.state[id].data;
}
}
exports Marty.register(BlockStore)
I'm not entirely happy with this solution but I can't think of a nicer way of doing it... One thing I'm considering is having a browserify transform which automatically wraps anything you export with, e.g. the above would become: var BlockStore = Marty.register(class _BlockStore { ... })
export BlockStore; |
Class! :) Thanks! The funny thing is that within all that trying I had a call to |
Now that React v0.13 is supporting ES6 classes its only a matter of time before the whole community goes that way. We should support ES6 classes out of the box. Fortunately the concepts in Marty largely map well to classes:
My major concern is how to map constants to action creators. I believe that the entire action function should have a type associated with it, not just when it dispatches. This was why we went with constants being functions. There have been some issues with this approach (#83) so would like to explore alternative solutions.
One idea I had is to use field annotations. I realise this isn't in a spec but neither is JSX. This would work out the box with Traceur however we need to support 6to5 and people using ES5. My suggestion is writing a annotation specific transformation (e.g. annotationify for browserify, equivalent for webpack and require.js). We would keep the original syntax for those who'd prefer it
Update
@KidkArolis has half convinced me its a bad idea to introduce annotations (although he agrees it solves the problem well. His suggestion was to call constants from inside the action function. This has the benefit that we don't have to mess with function contexts or introduce new tooling.
The other possible solution would be to define the types in a hash. On the upside its simpler and follows the same syntax as Stores, on the downside it does require a little mental work to work out which type is associated with an action creator.
The text was updated successfully, but these errors were encountered: