UK
Форум

Методологія

Інструментарій

Платформа

Перевод этой статьи на ваш язык отсутствует, вы можете помочь нам перевести.

graph

NPM Status

Install

$ npm install --save-dev @bem/sdk.graph

Usage

const BemGraph = require('@bem/sdk.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:

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.

doc-rating:rate
Повідомити про помилку на Гітхабі або поправити за допомогою prose.io.