Skip to content
This repository was archived by the owner on Feb 4, 2018. It is now read-only.

Commit c7646b8

Browse files
committed
fix: stop using bem-naming for generating id
1 parent 7d6297d commit c7646b8

File tree

4 files changed

+30
-43
lines changed

4 files changed

+30
-43
lines changed

lib/entity-name.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
const util = require('util');
44

5-
const stringifyEntity = require('@bem/naming').stringify;
6-
75
const deprecate = require('./deprecate');
86
const EntityTypeError = require('./entity-type-error');
97

@@ -205,7 +203,12 @@ class BemEntityName {
205203
get id() {
206204
if (this._id) { return this._id; }
207205

208-
this._id = stringifyEntity(this._data);
206+
const e = this._data;
207+
208+
this._id = e.block +
209+
(!e.elem ? '' : '__' + e.elem) +
210+
(!e.mod ? '' : '_' + e.mod.name +
211+
(e.mod.val === true ? '' : '_' + e.mod.val));
209212

210213
return this._id;
211214
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"node": ">= 4.0"
3434
},
3535
"dependencies": {
36-
"@bem/naming": "2.0.0-5",
3736
"depd": "1.1.0",
3837
"es6-error": "4.0.2"
3938
},

test/id.test.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import test from 'ava';
2-
import sinon from 'sinon';
3-
import proxyquire from 'proxyquire';
42

53
import BemEntityName from '..';
64

@@ -18,19 +16,10 @@ test('should build not equal id for not equal blocks', t => {
1816
t.not(entityName1.id, entityName2.id);
1917
});
2018

21-
test('should cache id value', t => {
22-
const stub = sinon.stub().returns('id');
23-
const StubBemEntityName = proxyquire('../lib/entity-name', {
24-
'@bem/naming': {
25-
stringify: stub
26-
}
27-
});
28-
29-
const entityName = new StubBemEntityName({ block: 'block' });
30-
31-
/*eslint no-unused-expressions: "off"*/
32-
entityName.id;
33-
entityName.id;
19+
test('should cache id for repeating calls', t => {
20+
const entityName1 = new BemEntityName({ block: 'block1' });
21+
const id = entityName1.id;
3422

35-
t.is(stub.callCount, 1);
23+
entityName1._data = {};
24+
t.is(id, entityName1.id);
3625
});

test/to-string.test.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
import test from 'ava';
2-
import sinon from 'sinon';
3-
import proxyquire from 'proxyquire';
4-
5-
const spy = sinon.spy();
6-
const BemEntityName = proxyquire('../lib/entity-name', {
7-
'@bem/naming': {
8-
stringify: spy
9-
}
10-
});
2+
import BemEntityName from '..';
113

12-
test('should use `naming.stringify()` for block', t => {
4+
test('should stringify block entity name', t => {
135
const entityName = new BemEntityName({ block: 'block' });
146

15-
entityName.toString();
16-
17-
t.true(spy.calledWith({ block: 'block' }));
7+
t.is(entityName.toString(), 'block');
188
});
199

20-
test('should use `naming.stringify()` for elem', t => {
10+
test('should stringify elem entity name', t => {
2111
const entityName = new BemEntityName({ block: 'block', elem: 'elem' });
2212

23-
entityName.toString();
13+
t.is(entityName.toString(), 'block__elem');
14+
});
15+
16+
test('should stringify block’s simple modifier entity name', t => {
17+
const entityName = new BemEntityName({ block: 'block', mod: { name: 'mod', val: true } });
2418

25-
t.true(spy.calledWith({ block: 'block', elem: 'elem' }));
19+
t.is(entityName.toString(), 'block_mod');
2620
});
2721

28-
test('should use `naming.stringify()` for block modifier', t => {
22+
test('should stringify block’s modifier entity name', t => {
2923
const entityName = new BemEntityName({ block: 'block', mod: { name: 'mod', val: 'val' } });
3024

31-
entityName.toString();
25+
t.is(entityName.toString(), 'block_mod_val');
26+
});
27+
28+
test('should stringify element’s simple modifier entity name', t => {
29+
const entityName = new BemEntityName({ block: 'block', elem: 'elem', mod: { name: 'mod', val: true } });
3230

33-
t.true(spy.calledWith({ block: 'block', mod: { name: 'mod', val: 'val' } }));
31+
t.is(entityName.toString(), 'block__elem_mod');
3432
});
3533

36-
test('should use naming.stringify() for element modifier', t => {
34+
test('should stringify element’s modifier entity name', t => {
3735
const entityName = new BemEntityName({ block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } });
3836

39-
entityName.toString();
40-
41-
t.true(spy.calledWith({ block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }));
37+
t.is(entityName.toString(), 'block__elem_mod_val');
4238
});

0 commit comments

Comments
 (0)