Skip to content

Instantly share code, notes, and snippets.

@peshi
Created February 5, 2017 12:06
Show Gist options
  • Save peshi/46df34027b27507fa0b14b6a4a3d35a4 to your computer and use it in GitHub Desktop.
Save peshi/46df34027b27507fa0b14b6a4a3d35a4 to your computer and use it in GitHub Desktop.
Drop in replacement for react-komposer 2 - Meteor.js
import { Tracker } from 'meteor/tracker';
import { compose } from 'react-komposer';
const getTrackerLoader = reactiveMapper => (
(props, onData, env) => {
let trackerCleanup = null;
const handler = Tracker.nonreactive(() =>
Tracker.autorun(() => {
// assign the custom clean-up function.
trackerCleanup = reactiveMapper(props, onData, env);
})
);
return () => {
if (typeof trackerCleanup === 'function') trackerCleanup();
return handler.stop();
};
}
);
const composeWithTracker = data => (
compose(getTrackerLoader(data))
);
export default composeWithTracker;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment