bem-graph

Bem graph storage


Keywords
bem, graph, entity, successors, dependencies
License
MPL-2.0
Install
npm install bem-graph@0.0.3

Documentation

bem-graph

NPM Status Travis Status Coverage Status Dependency Status

Install

$ npm install --save-dev bem-graph

Usage

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' }
// ]

API

BemGraph based on BemEntityName objects and bem-decl format.

BemGraph.vertex

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

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

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.

BemGraph~Vertex.dependsOn

Vertex.dependsOn(entityName: BemEntityName, tech: String): BemGraph~Vertex

Creates an ordered link between contained and passed vertices.

BemGraph~Vertex.linkWith

Vertex.linkWith(entityName: BemEntityName, tech: String): BemGraph~Vertex

Creates an unordered link between contained and passed vertices.

License

Code and documentation copyright 2016 YANDEX LLC. Code released under the Mozilla Public License 2.0.