Skip to content

Commit

Permalink
feat: add legacy getters for entity
Browse files Browse the repository at this point in the history
  • Loading branch information
qfox committed Feb 2, 2017
1 parent 8d5683c commit 7e83b7a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -35,7 +35,7 @@ const BemCell = require('@bem/cell');
const BemEntityName = require('@bem/entity-name');

const cell = new BemCell({
entity: new BemEntityName({ block: 'button', elem: 'text' }),
entity: new BemEntityName({ block: 'button', elem: 'text', mod: { name: 'theme', val: 'simple' } }),
tech: 'css',
layer: 'common'
});
Expand All @@ -44,6 +44,10 @@ cell.entity; // ➜ BemEntityName { block: 'button', elem: 'text' }
cell.tech; // css
cell.layer; // common
cell.id; // button__text@common.css

cell.block; // → button
cell.elem; // → text
cell.mod; // → { name: 'theme', val: 'simple' }
```

API
Expand Down
37 changes: 37 additions & 0 deletions index.js
Expand Up @@ -74,6 +74,43 @@ module.exports = class BemCell {
*/
get layer() { return this._layer; }

/**
* Proxies `block` field from entity.
*
* @returns {String}
*/
get block() { return this._entity.block; }

/**
* Proxies `elem` field from entity.
*
* @returns {String}
*/
get elem() { return this._entity.elem; }

/**
* Proxies `mod` field from entity.
*
* @returns {Object|undefined} - field with `name` and `val`
*/
get mod() { return this._entity.mod; }

/**
* Proxies `modVal` field from entity.
*
* @deprecated - just for compatibility and can be dropped in future
* @returns {String|undefined} - modifier name
*/
get modName() { return this._entity.modName; }

/**
* Proxies `modName` field from entity.
*
* @deprecated - just for compatibility and can be dropped in future
* @returns {String|'true'|undefined} - modifier value
*/
get modVal() { return this._entity.modVal; }

/**
* Returns the identifier of this cell.
*
Expand Down
40 changes: 40 additions & 0 deletions test/legacy.test.js
@@ -0,0 +1,40 @@
const test = require('ava');

const BemEntityName = require('@bem/entity-name');

const BemCell = require('../index');

const cell = new BemCell({ entity: new BemEntityName({ block: 'b', elem: 'e', mod: { name: 'm', val: 'v' } }) });
const modLessCell = new BemCell({ entity: new BemEntityName({ block: 'b' }) });

test('should return block field from entity', t => {
t.is(cell.block, cell.entity.block);
});

test('should return elem field from entity', t => {
t.is(cell.elem, cell.entity.elem);
});

test('should return modName field from entity', t => {
t.is(cell.modName, cell.entity.modName);
});

test('should return modVal field from entity', t => {
t.is(cell.modVal, cell.entity.modVal);
});

test('should return mod field from entity', t => {
t.deepEqual(cell.mod, cell.entity.mod);
});

test('should return undefined for modName field from entity', t => {
t.is(modLessCell.modName, undefined);
});

test('should return undefined for modVal field from entity', t => {
t.is(modLessCell.modVal, undefined);
});

test('should return undefined for mod field from entity', t => {
t.is(modLessCell.mod, undefined);
});

0 comments on commit 7e83b7a

Please sign in to comment.