Skip to content

Commit

Permalink
chore(types): add types to GraphHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLarkInn committed May 4, 2018
1 parent e361ba5 commit 19bd475
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/DependenciesBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

const DependenciesBlockVariable = require("./DependenciesBlockVariable");

/** @typedef {import("./ChunkGroup")} ChunkGroup */

class DependenciesBlock {
constructor() {
this.dependencies = [];
this.blocks = [];
this.variables = [];
/** @type {ChunkGroup=} */
this.chunkGroup = undefined;
}

addBlock(block) {
Expand Down
46 changes: 41 additions & 5 deletions lib/GraphHelpers.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,64 @@
exports.connectChunkGroupAndChunk = (chunkGroup, chunk) => {
/** @typedef {import("./Chunk")} Chunk */
/** @typedef {import("./ChunkGroup")} ChunkGroup */
/** @typedef {import("./Module")} Module */
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */

/**
* @param {ChunkGroup} chunkGroup the ChunkGroup to connect
* @param {Chunk} chunk chunk to tie to ChunkGroup
* @returns {void}
*/
const connectChunkGroupAndChunk = (chunkGroup, chunk) => {
if (chunkGroup.pushChunk(chunk)) {
chunk.addGroup(chunkGroup);
}
};

exports.connectChunkGroupParentAndChild = (parent, child) => {
/**
* @param {ChunkGroup} parent parent ChunkGroup to connect
* @param {ChunkGroup} child child ChunkGroup to connect
* @returns {void}
*/
const connectChunkGroupParentAndChild = (parent, child) => {
if (parent.addChild(child)) {
child.addParent(parent);
}
};

exports.connectChunkAndModule = (chunk, module) => {
/**
* @param {Chunk} chunk Chunk to connect to Module
* @param {Module} module Module to connect to Chunk
* @returns {void}
*/
const connectChunkAndModule = (chunk, module) => {
if (module.addChunk(chunk)) {
chunk.addModule(module);
}
};

exports.disconnectChunkAndModule = (chunk, module) => {
/**
* @param {Chunk} chunk Chunk being disconnected
* @param {Module} module Module being disconnected
* @returns {void}
*/
const disconnectChunkAndModule = (chunk, module) => {
chunk.removeModule(module);
module.removeChunk(chunk);
};

exports.connectDependenciesBlockAndChunkGroup = (depBlock, chunkGroup) => {
/**
* @param {DependenciesBlock} depBlock DepBlock being tied to ChunkGroup
* @param {ChunkGroup} chunkGroup ChunkGroup being tied to DepBlock
* @returns {void}
*/
const connectDependenciesBlockAndChunkGroup = (depBlock, chunkGroup) => {
if (chunkGroup.addBlock(depBlock)) {
depBlock.chunkGroup = chunkGroup;
}
};

exports.connectChunkGroupAndChunk = connectChunkGroupAndChunk;
exports.connectChunkGroupParentAndChild = connectChunkGroupParentAndChild;
exports.connectChunkAndModule = connectChunkAndModule;
exports.disconnectChunkAndModule = disconnectChunkAndModule;
exports.connectDependenciesBlockAndChunkGroup = connectDependenciesBlockAndChunkGroup;

0 comments on commit 19bd475

Please sign in to comment.