This repository was archived by the owner on Feb 4, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,36 @@ class BemEntityName {
156
156
return this . _type ;
157
157
}
158
158
159
+ /**
160
+ * Returns scope of this entity.
161
+ *
162
+ * Important: block-typed entities has no scope.
163
+ *
164
+ * @example
165
+ * const BemEntityName = require('@bem/entity-name');
166
+ *
167
+ * const buttonName = new BemEntityName({ block: 'button' });
168
+ * const buttonTextName = new BemEntityName({ block: 'button', elem: 'text' });
169
+ * const buttonTextBoldName = new BemEntityName({ block: 'button', elem: 'text', mod: 'bold' });
170
+ *
171
+ * buttonName.scope; // null
172
+ * buttonTextName.scope; // BemEntityName { block: 'button' }
173
+ * buttonTextBoldName.scope; // BemEntityName { block: 'button', elem: 'elem' }
174
+ *
175
+ * @returns {BemEntityName } - scope entity name.
176
+ */
177
+ get scope ( ) {
178
+ if ( this . type === TYPES . BLOCK ) { return null ; }
179
+ if ( this . _scope ) { return this . _scope ; }
180
+
181
+ this . _scope = new BemEntityName ( {
182
+ block : this . block ,
183
+ elem : this . type === TYPES . ELEM_MOD && this . elem
184
+ } ) ;
185
+
186
+ return this . _scope ;
187
+ }
188
+
159
189
/**
160
190
* Returns id for this entity.
161
191
*
@@ -238,6 +268,7 @@ class BemEntityName {
238
268
*
239
269
* buttonTextName.belongsTo(buttonName); // true
240
270
* buttonName.belongsTo(buttonTextName); // false
271
+ *
241
272
* buttonTextBoldName.belongsTo(buttonTextName); // true
242
273
* buttonTextBoldName.belongsTo(buttonName); // false
243
274
*
You can’t perform that action at this time.
0 commit comments