-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
š Make
Blast.executeAfterLoadingCycle()
keep did_initial_load
varā¦
ā¦iable alone
- Loading branch information
Showing
4 changed files
with
90 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -665,7 +665,7 @@ Blast.defineStatic('Function', function inherits(_parent, _namespace, _newConstr | |
// Add the parent constitutors to the new constructor | ||
if (newConstructor.super.constitutors != null) { | ||
for (i = 0; i < newConstructor.super.constitutors.length; i++) { | ||
newConstructor.constitute(newConstructor.super.constitutors[i]); | ||
addConstructorConstitutor(newConstructor, newConstructor.super.constitutors[i], true); | ||
} | ||
}; | ||
|
||
|
@@ -674,7 +674,7 @@ Blast.defineStatic('Function', function inherits(_parent, _namespace, _newConstr | |
} | ||
|
||
for (i = 0; i < oldProto.waitingConstitute.length; i++) { | ||
newConstructor.constitute(oldProto.waitingConstitute[i]); | ||
addConstructorConstitutor(newConstructor, oldProto.waitingConstitute[i], true); | ||
} | ||
|
||
doPostInheritors(newConstructor); | ||
|
@@ -1235,7 +1235,7 @@ defClassMethod(function postInherit(constructor, task) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.1.4 | ||
* @version 0.8.18 | ||
* @version 0.9.0 | ||
* | ||
* @param {Function} constructor | ||
* @param {Function} task | ||
|
@@ -1247,6 +1247,21 @@ defClassMethod(function constitute(constructor, task) { | |
return; | ||
} | ||
|
||
addConstructorConstitutor(constructor, task, false); | ||
}); | ||
|
||
/** | ||
* Actually add and maybe execute the constitutor to the given constructor | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.9.0 | ||
* @version 0.9.0 | ||
* | ||
* @param {Function} constructor | ||
* @param {Function} task | ||
*/ | ||
function addConstructorConstitutor(constructor, task, after_wait = false) { | ||
|
||
let tasks = constructor.constitutors; | ||
|
||
if (tasks == null) { | ||
|
@@ -1269,6 +1284,10 @@ defClassMethod(function constitute(constructor, task) { | |
doConstructorTask(constructor, task, finished_constitutors); | ||
}); | ||
} | ||
} else if (Blast.didInitialLoad()) { | ||
Blast.loaded(() => { | ||
doConstructorTask(constructor, task, finished_constitutors); | ||
}); | ||
} | ||
|
||
// If this class already has children, add them there too | ||
|
@@ -1277,11 +1296,11 @@ defClassMethod(function constitute(constructor, task) { | |
|
||
for (child of constructor.children) { | ||
if (!child.constitutors || child.constitutors.indexOf(task) == -1) { | ||
constitute(child, task); | ||
child.constitute(task); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Add a class instance as a static property and add static traits | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -991,11 +991,12 @@ function BlastInit(modifyPrototype) { | |
require('./server_functions.js')(Blast, extras); | ||
//PROTOBLAST END CUT | ||
|
||
var when_ready = [], | ||
let when_ready = [], | ||
when_loaded = [], | ||
queued_meds = [], | ||
queued_ticks = [], | ||
did_initial_load = false; | ||
did_initial_load = false, | ||
temporarily_unready = false; | ||
|
||
/** | ||
* Execute function after Blast code has run. | ||
|
@@ -1122,7 +1123,7 @@ function BlastInit(modifyPrototype) { | |
* @return {Boolean} Returns if Protoblast is already ready | ||
*/ | ||
Blast.ready = function ready(fnc) { | ||
if (when_ready) { | ||
if (when_ready || temporarily_unready) { | ||
|
||
if (fnc) { | ||
when_ready.push(fnc); | ||
|
@@ -1151,7 +1152,7 @@ function BlastInit(modifyPrototype) { | |
* @return {Boolean} Returns if Protoblast has already loaded | ||
*/ | ||
Blast.loaded = function loaded(fnc) { | ||
if (!did_initial_load) { | ||
if (!did_initial_load || temporarily_unready) { | ||
|
||
if (fnc) { | ||
when_loaded.push(fnc); | ||
|
@@ -1168,6 +1169,28 @@ function BlastInit(modifyPrototype) { | |
} | ||
}; | ||
|
||
/** | ||
* Did the initial load already happen? | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.9.0 | ||
* @version 0.9.0 | ||
* | ||
* @return {boolean} | ||
*/ | ||
Blast.didInitialLoad = () => did_initial_load; | ||
|
||
/** | ||
* Are we currently in a manual loading cycle? | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.9.0 | ||
* @version 0.9.0 | ||
* | ||
* @return {boolean} | ||
*/ | ||
Blast.inLoadingCycle = () => temporarily_unready; | ||
|
||
/** | ||
* Force Protoblast into executing the when_loaded functions | ||
* | ||
|
@@ -1177,17 +1200,18 @@ function BlastInit(modifyPrototype) { | |
*/ | ||
Blast.doLoaded = function doLoaded() { | ||
|
||
if (!did_initial_load) { | ||
if (!did_initial_load || temporarily_unready) { | ||
Blast.loading = true; | ||
} | ||
|
||
doQueuedTicks(); | ||
clearAndDoTasks(queued_meds); | ||
clearAndDoTasks(when_loaded); | ||
|
||
if (!did_initial_load) { | ||
if (!did_initial_load || temporarily_unready) { | ||
Blast.loading = false; | ||
did_initial_load = true; | ||
temporarily_unready = false; | ||
} | ||
}; | ||
|
||
|
@@ -1202,14 +1226,14 @@ function BlastInit(modifyPrototype) { | |
*/ | ||
Blast.executeAfterLoadingCycle = function executeAfterLoadingCycle(task) { | ||
|
||
if (!did_initial_load) { | ||
if (!did_initial_load || temporarily_unready) { | ||
Blast.loaded(task); | ||
return; | ||
} | ||
|
||
did_initial_load = false; | ||
temporarily_unready = true; | ||
Blast.loaded(task); | ||
|
||
Blast.setImmediate(() => { | ||
Blast.doLoaded(); | ||
}); | ||
|
This file contains 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