Skip to content

Commit

Permalink
remove need to wait
Browse files Browse the repository at this point in the history
avoid need for specific execution order on startup, and the need for FastRender.wait()
  • Loading branch information
copleykj committed May 6, 2021
1 parent 175aad6 commit 3a78e32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 35 deletions.
14 changes: 6 additions & 8 deletions lib/client/boot.js
Expand Up @@ -3,13 +3,11 @@ import { FastRender } from './fast_render';
import { InjectData } from 'meteor/communitypackages:inject-data';

Meteor.startup(function () {
if (!FastRender._wait) {
InjectData.getData('fast-render-data', function (payload) {
FastRender.init(payload);
InjectData.getData('fast-render-data', function (payload) {
FastRender.init(payload);
InjectData.getData('fast-render-extra-data', function (extraDataPayload) {
FastRender._setExtraData(extraDataPayload);
FastRender._setDataReady();
});

InjectData.getData('fast-render-extra-data', function (payload) {
FastRender._setExtraData(payload);
});
}
});
});
50 changes: 23 additions & 27 deletions lib/client/fast_render.js
@@ -1,7 +1,6 @@
/* global location */
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { InjectData } from 'meteor/communitypackages:inject-data';
import { onPageLoad } from 'meteor/server-render';
import { IDTools } from './id_tools';

Expand All @@ -13,6 +12,8 @@ let extraneousData = {};

export const FastRender = {
_dataReceived: false,
_dataReadyCallback: null,
_dataReady: false,
_revertedBackToOriginal: false,
IDTools,
_blockDDP: Meteor._localStorage.getItem('__frblockddp') !== null,
Expand Down Expand Up @@ -79,22 +80,6 @@ export const FastRender = {
},
},

wait () {
FastRender._wait = true;
},

onDataReady (callback) {
FastRender.wait();

InjectData.getData('fast-render-data', function (data) {
FastRender.init(data);
InjectData.getData('fast-render-extra-data', function (payload) {
FastRender._setExtraData(payload);
callback();
});
});
},

// This allow us to apply DDP message even if Meteor block accepting messages
// When doing initial login, Meteor sends an login message
// Then it'll block the accpeting DDP messages from server
Expand Down Expand Up @@ -132,7 +117,6 @@ export const FastRender = {
},

init (payload) {
console.log('init called');
if (FastRender._disable) return;

FastRender._securityCheck(payload);
Expand Down Expand Up @@ -301,19 +285,31 @@ export const FastRender = {
return obj;
},

onDataReady (callback) {
FastRender._runIfDataReady(callback);
},

onPageLoad (callback) {
FastRender.wait();
console.log(FastRender._wait);
onPageLoad(sink => {
InjectData.getData('fast-render-data', function (data) {
FastRender.init(data);
InjectData.getData('fast-render-extra-data', function (payload) {
FastRender._setExtraData(payload);
callback(sink);
});
});
FastRender._runIfDataReady(() => callback(sink));
});
},

_setDataReady () {
if (FastRender._dataReadyCallback !== null && typeof FastRender._dataReadyCallback === 'function') {
FastRender._dataReadyCallback();
} else {
FastRender._dataReady = true;
}
},

_runIfDataReady (callback) {
if (FastRender._dataReady) {
callback();
} else {
FastRender._dataReadyCallback = callback;
}
},
};

if (FastRender._blockDDP) {
Expand Down

0 comments on commit 3a78e32

Please sign in to comment.