Rearrange Actor instances so exceptions during construction are correctly blamed on the new actor
This commit is contained in:
parent
160938cec8
commit
d777418d5c
47
src/actor.js
47
src/actor.js
|
@ -5,16 +5,22 @@ var Route = Minimart.Route;
|
||||||
|
|
||||||
Actor._chunks = null;
|
Actor._chunks = null;
|
||||||
|
|
||||||
function Actor(ctor) {
|
function Actor(bootfn) {
|
||||||
var oldChunks = Actor._chunks;
|
return {
|
||||||
try {
|
boot: function () {
|
||||||
|
delete this.boot;
|
||||||
|
var oldChunks = Actor._chunks;
|
||||||
|
try {
|
||||||
Actor._chunks = [];
|
Actor._chunks = [];
|
||||||
var behavior = new ctor();
|
bootfn.call(this);
|
||||||
return finalizeActor(behavior, Actor._chunks);
|
finalizeActor(this, Actor._chunks);
|
||||||
} catch (e) {
|
Actor._chunks = oldChunks;
|
||||||
|
} catch (e) {
|
||||||
Actor._chunks = oldChunks;
|
Actor._chunks = oldChunks;
|
||||||
throw e;
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkChunks(type) {
|
function checkChunks(type) {
|
||||||
|
@ -112,27 +118,11 @@ Actor.observeGestalt = function (gestaltFn, eventHandlerFn) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function finalizeActor(behavior, chunks) {
|
function finalizeActor(behavior, chunks) {
|
||||||
var oldBoot = behavior.boot;
|
|
||||||
var oldHandleEvent = behavior.handleEvent;
|
var oldHandleEvent = behavior.handleEvent;
|
||||||
var projections = {};
|
var projections = {};
|
||||||
var compiledProjections = {};
|
var compiledProjections = {};
|
||||||
var previousObjs = {};
|
var previousObjs = {};
|
||||||
|
|
||||||
behavior.boot = function () {
|
|
||||||
if (oldBoot) { oldBoot.call(this); }
|
|
||||||
for (var i = 0; i < chunks.length; i++) {
|
|
||||||
var chunk = chunks[i];
|
|
||||||
if (chunk.kind === 'observer') {
|
|
||||||
if (chunk.options.presence) { this[chunk.options.presence] = false; }
|
|
||||||
if (chunk.options.name) { this[chunk.options.name] = []; }
|
|
||||||
if (chunk.options.singleton) { this[chunk.options.singleton] = undefined; }
|
|
||||||
if (chunk.options.added) { this[chunk.options.added] = []; }
|
|
||||||
if (chunk.options.removed) { this[chunk.options.removed] = []; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.updateRoutes();
|
|
||||||
};
|
|
||||||
|
|
||||||
behavior.updateRoutes = function () {
|
behavior.updateRoutes = function () {
|
||||||
var newRoutes = Route.emptyGestalt;
|
var newRoutes = Route.emptyGestalt;
|
||||||
for (var i = 0; i < chunks.length; i++) {
|
for (var i = 0; i < chunks.length; i++) {
|
||||||
|
@ -253,7 +243,18 @@ function finalizeActor(behavior, chunks) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return behavior;
|
if (behavior.boot) { behavior.boot(); }
|
||||||
|
for (var i = 0; i < chunks.length; i++) {
|
||||||
|
var chunk = chunks[i];
|
||||||
|
if (chunk.kind === 'observer') {
|
||||||
|
if (chunk.options.presence) { behavior[chunk.options.presence] = false; }
|
||||||
|
if (chunk.options.name) { behavior[chunk.options.name] = []; }
|
||||||
|
if (chunk.options.singleton) { behavior[chunk.options.singleton] = undefined; }
|
||||||
|
if (chunk.options.added) { behavior[chunk.options.added] = []; }
|
||||||
|
if (chunk.options.removed) { behavior[chunk.options.removed] = []; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
behavior.updateRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
function kwApply(f, thisArg, args) {
|
function kwApply(f, thisArg, args) {
|
||||||
|
|
Loading…
Reference in New Issue