Created
February 5, 2017 12:06
-
-
Save peshi/46df34027b27507fa0b14b6a4a3d35a4 to your computer and use it in GitHub Desktop.
Drop in replacement for react-komposer 2 - Meteor.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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