-
Notifications
You must be signed in to change notification settings - Fork 141
Allow lazy fragment initializaiton through promise #94
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would restructure this to have something like:
function doInit(init, callback) {
// do actual initialization and when done do callback
}
doInit(init, measureInitCost.bind(null, fragmentId, 'fragment-');
That way you can avoid multiple early returns.
// Check if the exposed function is a Promise to allow lazy rendering | ||
// Capture initializaion cost of each fragment on the page using User Timing API if available | ||
if (isPromise(init)) { | ||
init.then(function(module) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that init
function should rather return a promise
// check if User Timing API is supported | ||
var isUTSupported = perf && 'mark' in perf; | ||
|
||
function isPromise(obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pull this out into a library function and import it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it simple.. will probably even inline it than keeping it as fn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe, but it's probably something that should be covered by a test, so pulling it out into a library func is going to help with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah i didnt do that since its not used anywhere other than this one place..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oki
fixes #92