Closed sdbondi closed 8 years ago
First of all, since you're using react
(official from MDG), you don't need to use reactjs:react
.
I just made a test app that uses your VotePage
component, and the console.log
is happening on change. How are you including the component?
Thanks, but I want to use ReactMeteor.createClass
which allows me to subscribe to publications without the getMeteorData() { var handler=Meteor.subscribe(...); if (ready()) { Entry.find(...);}}
stuff - this gets a bit unwieldy in my app.
I have not found a better way when using the ReactMeterData
mixin and I watched this tallk so I gave reactjs:react
a try - it worked with some work arounds :( I've tried to eliminate the Meteor stuff from my trouble area and I can't narrow it down to the Meteor stuff as the component doesn't work either way. I'm open to using the mixin though.
Anyway I am using ReactLayout
and FlowRouter
var publicGroup = FlowRouter.group({});
publicGroup.route('/vote', {
name: 'vote',
action() {
ReactLayout.render(AppLayout, {
content: <Pages.VotePage />
})
}
});
That class in the issue is Page.VotePage.
I don't really like either ReactMeteorData or ReactMeteor for subscriptions. Instead I start the subscriptions in my iron-router's waitOn (not sure if there's something similar in FlowRouter), and then in the component I do this:
compoentWillMount() {
this.handle = Deps.autorun(() => {
var votes = Votes.find({ election: this.props.electionId }).fetch();
this.setState({ votes });
});
},
componentWillUnmount() {
this.handle.stop();
},
I like doing it this way since I can decide when I want to update the state and control what's reactive (this is important e.g. in some cases for drag and drop).
Anyway, sorry I can't help you figure out your onChange problem.
Actually you have! Well I still have no idea why it broke, but just removing reactjs:react
and just having the react package + removing all the ReactMeteor
classes for now and the component above works!
FlowRouter
does have a subscribe mechanism so I'll play with that, might put that in a statics:{ subscriptions(){} }
and call Page.VotePage.subscriptions()
or something as I prefer seeing what the component needs inside the component.
Thanks for your help - closing!
Oh that's interesting. It still worked in my test app with both packages.
No problem and good luck with your app!
Ye so many deps, packages and reacts going on - really tricky to track down, will work on minimizing them later - thanks for taking the time to help, my first production meteor/react app - been interesting, not as quick as I'd hoped but great fun!
BTW I made this mixin (may not like em, but they can make things work in a bind):
export const MeteorReactSubscriber = {
componentWillMount() {
this._subsMap = {};
this.subscriptions();
this._startMeteorTracker();
},
_startMeteorTracker() {
this._subsHandle = Tracker.autorun(() => {
this.subscriptionReady && this.subscriptionReady();
if (this.meteorSubsReady()) {
this.meteorDataReady && this.meteorDataReady();
}
});
},
meteorSubsReady() {
return _.all(this._subsMap, (s, _) => s.ready());
},
meteorSubscribe(name, selector=undefined) {
this._subsMap[name] = Meteor.subscribe(name, selector);
},
componentWillUnmount() {
this._subsHandle.stop();
this._subsMap = null;
}
};
var SweetComponent = React.createClass({
mixins: [MeteorReactSubscriber],
subscriptions() {
this.meteorSubscribe('entries');
},
meteorDataReady() {
var currentEntry = Entry.findOne(this.props.entryId);
this.setState({entry});
}
});
A very basic and standard component which should call the change handler when the input changes. It works in my pen: http://codepen.io/sdbondi/pen/MaGovq
It doesn't in my meteor app - in fact any handler (onClick, etc) doesn't work if rendered after the initial page load - { (this.state.cond) ?
<Element onChange={..}/>
: ''} will also render but not fire the change.Interestingly changes fire if I set the entries in the initial state, but with setTimeout they render but no onChange.
I've stepped through react to try and understand how events are bound (I actually got to
addEventListener
eventually) but it'll take a while to understand what is happening enough to debug.