Skip to content

Commit

Permalink
pending sources as Set
Browse files Browse the repository at this point in the history
  • Loading branch information
paed01 committed Jun 14, 2024
1 parent 4b38712 commit b3ee49b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
15 changes: 8 additions & 7 deletions lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ function Engine(options = {}) {
this[kExecution] = null;
this[kLoadedDefinitions] = null;

const pendingSources = (this[kPendingSources] = []);
if (opts.source) pendingSources.push(this._serializeSource(opts.source));
if (opts.moddleContext) pendingSources.push(this._serializeModdleContext(opts.moddleContext));
if (opts.sourceContext) pendingSources.push(opts.sourceContext);
const pendingSources = (this[kPendingSources] = new Set());
if (opts.source) pendingSources.add(this._serializeSource(opts.source));
if (opts.moddleContext) pendingSources.add(this._serializeModdleContext(opts.moddleContext));
if (opts.sourceContext) pendingSources.add(opts.sourceContext);
}

function defaultTypeResolver(elementTypes) {
Expand Down Expand Up @@ -293,15 +293,16 @@ Engine.prototype.recover = function recover(savedState, recoverOptions) {
if (!savedState.definitions) return this;

const pendingSources = this[kPendingSources];
const preSources = pendingSources.splice(0);
const preSources = [...pendingSources];
pendingSources.clear();

const typeResolver = this[kTypeResolver];
const loadedDefinitions = (this[kLoadedDefinitions] = savedState.definitions.map((dState) => {
let source;
if (dState.source) source = serializer.deserialize(JSON.parse(dState.source), typeResolver);
else source = preSources.find((s) => s.id === dState.id);

pendingSources.push(source);
pendingSources.add(source);

this.logger.debug(`<${name}> recover ${dState.type} <${dState.id}>`);

Expand Down Expand Up @@ -337,7 +338,7 @@ Engine.prototype.addSource = function addSource({ sourceContext: addContext } =
if (!addContext) return;
const loadedDefinitions = this[kLoadedDefinitions];
if (loadedDefinitions) loadedDefinitions.splice(0);
this[kPendingSources].push(addContext);
this[kPendingSources].add(addContext);
};

Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
Expand Down
15 changes: 8 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export function Engine(options = {}) {
this[kExecution] = null;
this[kLoadedDefinitions] = null;

const pendingSources = (this[kPendingSources] = []);
if (opts.source) pendingSources.push(this._serializeSource(opts.source));
if (opts.moddleContext) pendingSources.push(this._serializeModdleContext(opts.moddleContext));
if (opts.sourceContext) pendingSources.push(opts.sourceContext);
const pendingSources = (this[kPendingSources] = new Set());
if (opts.source) pendingSources.add(this._serializeSource(opts.source));
if (opts.moddleContext) pendingSources.add(this._serializeModdleContext(opts.moddleContext));
if (opts.sourceContext) pendingSources.add(opts.sourceContext);
}

function defaultTypeResolver(elementTypes) {
Expand Down Expand Up @@ -147,15 +147,16 @@ Engine.prototype.recover = function recover(savedState, recoverOptions) {
if (!savedState.definitions) return this;

const pendingSources = this[kPendingSources];
const preSources = pendingSources.splice(0);
const preSources = [...pendingSources];
pendingSources.clear();

const typeResolver = this[kTypeResolver];
const loadedDefinitions = (this[kLoadedDefinitions] = savedState.definitions.map((dState) => {
let source;
if (dState.source) source = deserialize(JSON.parse(dState.source), typeResolver);
else source = preSources.find((s) => s.id === dState.id);

pendingSources.push(source);
pendingSources.add(source);

this.logger.debug(`<${name}> recover ${dState.type} <${dState.id}>`);

Expand Down Expand Up @@ -191,7 +192,7 @@ Engine.prototype.addSource = function addSource({ sourceContext: addContext } =
if (!addContext) return;
const loadedDefinitions = this[kLoadedDefinitions];
if (loadedDefinitions) loadedDefinitions.splice(0);
this[kPendingSources].push(addContext);
this[kPendingSources].add(addContext);
};

Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
Expand Down

0 comments on commit b3ee49b

Please sign in to comment.