$ npm install --save-dev bem-graph
const BemGraph = require('bem-graph');
const graph = new BemGraph();
graph.vertex({ block: 'attach' }, 'js')
.dependsOn({ block: 'button' }, 'bemhtml');
graph.vertex({ block: 'button' })
.linkWith({ block: 'button', elem: 'text' });
graph.vertex({ block: 'textarea' }, 'css')
.dependsOn({ block: 'input' }, 'css');
const decl = [
{ block: 'attach' },
{ block: 'textarea' },
{ block: 'button' }
];
graph.dependenciesOf(decl, 'css');
// [
// { entity: { block: 'attach' }, tech: 'css' },
// { entity: { block: 'textarea' }, tech: 'css' },
// { entity: { block: 'input' }, tech: 'css' },
// { entity: { block: 'button' }, tech: 'css' },
// { entity: { block: 'button', elem: 'text' }, tech: 'css' }
// ]
graph.dependenciesOf(decl, 'js');
// [
// { entity: { block: 'button' }, tech: 'bemhtml' },
// { entity: { block: 'attach' }, tech: 'js' },
// { entity: { block: 'button', elem: 'text' }, tech: 'bemhtml' },
// { entity: { block: 'textarea' }, tech: 'js' }
// ]
BemGraph based on BemEntityName objects and bem-decl format.
BemGraph.vertex(entityName: BemEntityName, tech: String): BemGraph~Vertex
Registers vertex in graph and makes a helper object BemGraph~Vertex
with methods
to link it with other vertices.
BemGraph.dependenciesOf(declaration: Array<BemEntityName>, tech: String):
Array<{entity: BemEntityName, tech: String}>
Resolves ordered declaration and returns .
NB: Will throw for cycles in ordered links.
BemGraph.naturalize(): void
Creates "natural" links between registered entities:
- element should depend on block;
- block modifier should also depend on block;
- element modifier should depend on element.
Vertex.dependsOn(entityName: BemEntityName, tech: String): BemGraph~Vertex
Creates an ordered link between contained and passed vertices.
Vertex.linkWith(entityName: BemEntityName, tech: String): BemGraph~Vertex
Creates an unordered link between contained and passed vertices.
Code and documentation copyright 2016 YANDEX LLC. Code released under the Mozilla Public License 2.0.