Skip to content

Commit

Permalink
simplfy by removing getter setter
Browse files Browse the repository at this point in the history
  • Loading branch information
AGawrys committed Aug 2, 2022
1 parent 8b21dc8 commit 461de02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
15 changes: 1 addition & 14 deletions packages/core/core/src/AssetGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
hash: ?string;
envCache: Map<string, Environment>;
symbolPropagationRan: boolean;
#unsafeToIncrementallyBundle: boolean = false;
safeToIncrementallyBundle: boolean = true;

constructor(opts: ?AssetGraphOpts) {
if (opts) {
let {hash, symbolPropagationRan, ...rest} = opts;
super(rest);
this.hash = hash;
this.symbolPropagationRan = symbolPropagationRan;
this.#unsafeToIncrementallyBundle = false;
} else {
super();
this.setRootNodeId(
Expand Down Expand Up @@ -627,16 +626,4 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
this.hash = hash.finish();
return this.hash;
}

markUnsafeToBundleIncrementally() {
this.#unsafeToIncrementallyBundle = true;
}

unmarkUnsafeToBundleIncrementally() {
this.#unsafeToIncrementallyBundle = false;
}

get unsafeToBundleIncrementally(): boolean {
return this.#unsafeToIncrementallyBundle;
}
}
20 changes: 11 additions & 9 deletions packages/core/core/src/requests/AssetGraphRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default function createAssetGraphRequest(
!input.options.shouldBundleIncrementally ||
input.options.mode === 'production'
) {
assetGraphRequest.assetGraph.markUnsafeToBundleIncrementally();
assetGraphRequest.assetGraph.safeToIncrementallyBundle = false;
}

return {
Expand Down Expand Up @@ -136,7 +136,7 @@ export class AssetGraphBuilder {
shouldBuildLazily,
} = input;
let assetGraph = prevResult?.assetGraph ?? new AssetGraph();
assetGraph.unmarkUnsafeToBundleIncrementally();
assetGraph.safeToIncrementallyBundle = true;
assetGraph.setRootConnections({
entries,
assetGroups,
Expand Down Expand Up @@ -870,7 +870,7 @@ export class AssetGraphBuilder {
}

async runEntryRequest(input: ProjectPath) {
let prevEntries = !this.assetGraph.unsafeToBundleIncrementally
let prevEntries = this.assetGraph.safeToIncrementallyBundle
? this.assetGraph
.getEntryAssets()
.map(asset => asset.id)
Expand All @@ -883,7 +883,7 @@ export class AssetGraphBuilder {
});
this.assetGraph.resolveEntry(request.input, result.entries, request.id);

if (!this.assetGraph.unsafeToBundleIncrementally) {
if (this.assetGraph.safeToIncrementallyBundle) {
let currentEntries = this.assetGraph
.getEntryAssets()
.map(asset => asset.id)
Expand All @@ -894,7 +894,9 @@ export class AssetGraphBuilder {
(entryId, index) => entryId === currentEntries[index],
);

didEntriesChange && this.assetGraph.markUnsafeToBundleIncrementally();
if (didEntriesChange) {
this.assetGraph.safeToIncrementallyBundle = false;
}
}
}

Expand Down Expand Up @@ -929,23 +931,23 @@ export class AssetGraphBuilder {

if (assets != null) {
for (let asset of assets) {
if (!this.assetGraph.unsafeToBundleIncrementally) {
if (this.assetGraph.safeToIncrementallyBundle) {
let otherAsset = this.assetGraph.getNodeByContentKey(asset.id);
if (otherAsset != null) {
invariant(otherAsset.type === 'asset');
if (!this._areDependenciesEqualForAssets(asset, otherAsset.value)) {
this.assetGraph.markUnsafeToBundleIncrementally();
this.assetGraph.safeToIncrementallyBundle = false;
}
} else {
// adding a new entry or dependency
this.assetGraph.markUnsafeToBundleIncrementally();
this.assetGraph.safeToIncrementallyBundle = false;
}
}
this.changedAssets.set(asset.id, asset);
}
this.assetGraph.resolveAssetGroup(input, assets, request.id);
} else {
this.assetGraph.markUnsafeToBundleIncrementally();
this.assetGraph.safeToIncrementallyBundle = false;
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/core/src/requests/BundleGraphRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class BundlerRunner {

// if a previous asset graph hash is passed in, check if the bundle graph is also available
let previousBundleGraphResult: ?BundleGraphRequestResult;
if (!graph.unsafeToBundleIncrementally && previousAssetGraphHash != null) {
if (graph.safeToIncrementallyBundle && previousAssetGraphHash != null) {
try {
previousBundleGraphResult =
await this.api.getRequestResult<BundleGraphRequestResult>(
Expand All @@ -248,15 +248,15 @@ class BundlerRunner {
previousBundleGraphResult == null ||
previousBundleGraphResult?.bundlerHash !== bundlerHash
) {
graph.markUnsafeToBundleIncrementally();
graph.safeToIncrementallyBundle = false;
}

let internalBundleGraph;

let logger = new PluginLogger({origin: name});

try {
if (!graph.unsafeToBundleIncrementally) {
if (graph.safeToIncrementallyBundle) {
internalBundleGraph = nullthrows(previousBundleGraphResult).bundleGraph;
for (let changedAsset of changedAssets.values()) {
internalBundleGraph.updateAsset(changedAsset);
Expand Down

0 comments on commit 461de02

Please sign in to comment.