bem-walk
bem-walk copied to clipboard
Ability to read just some part of level instead of full walk
Is this the same as "Ability to stop walking at some point"?
Now you can scan levels only fully:
var walk = require('bem-walk');
walk(['blocks']) // scan all entities in specified levels
For me partial scan suggests API which uses the path:
var walk = require('bem-walk');
walk('blocks/button') // scan block with its elements and its mods
walk('blocks/button/_mod') // scan mods of block
walk('blocks/button/__elem') // scan elem with its mods
But for flat level scheme it may look different:
var walk = require('bem-walk'),
opts = { scheme: 'flat' };
walk('blocks/button', opts) // scan block with its elements and its mods
walk('blocks/button_mod', opts) // scan mod of block
walk('blocks/button__elem', opts) // scan elem
:+1: :+1: :+1:
Okay, let's move to #16 then.
@zxqfox, it's a different issues ;)
:+1: :+1: :+1:
А у Жеки 3 руки! ))
Это я просто очень рад ;)
@andrewblond If you've made #16 this task will go higher to builder or level-configurator. What's for we need it in walker?
@andrewblond If you've made #16 this task will go higher to builder or level-configurator. What's for we need it in walker?
Now there is no possibility to scan only part of the level. Issue #16 will not help to scan levels partially.
I removed wildcards from the description of this issue.
I think better to just make a stop method («горшочек не вари») used to prevent further walking.
upd I'm not sure that this issue is critical because of #20
Isn't it more common for streams to have special events for each kind of thing we're looking for? Like this:
var walk = require('bem-walk');
walk(['common.blocks', 'desktop.blocks']).on('entity') // same as walk(['common.blocks', 'desktop.blocks'])
walk(['common.blocks', 'desktop.blocks']).on('block') // all blocks, ignore elems and mods
walk(['common.blocks', 'desktop.blocks']).on({ block: 'button' }) // same as walk('*.blocks/button')
walk(['common.blocks', 'desktop.blocks']).on({ block: 'button' }) — are you sure you really need this? What is the case to use that? What if this block uses another block?
Isn't it more common for streams to have special events for each kind of thing we're looking for?
There is issue #21 about it
What is the case to use that?
the case is the same as in @andrewblond's suggestion to get just all techs of current block and its elements and mods
There is issue #21 about it
alright then :)
to get just all techs of current block and its elements and mods
I can't get what for?
e.g. to provide block info on bem.info
We can calculate depth of level in core for file or dir and provide this info to schemes (schemes should support depth field in info option).
The depth calculate by the number of / in path from level dirname:
level — 0
level/dir1 — 1
level/dir1/dir2 — 2
Example:
bemconf.js
common.blocks/
button/
button.css
button.js
desktop.blocks/
Scan project files
const config = require('bem-config')();
const walk = require('bem-walk');
const levelMap = config.levelMapSync();
walk({ levels: levelMap });
// depth for 'common.blocks' path is -1
// it is mean that need scan all levels in this directory
Scan the level
const config = require('bem-config')();
const walk = require('bem-walk');
const levelMap = config.levelMapSync();
walk('common.blocks', { levels: levelMap });
// depth for 'common.blocks' path is 0
Scan only button files
const config = require('bem-config')();
const walk = require('bem-walk');
const levelMap = config.levelMapSync();
walk('common.blocks/button', { levels: levelMap });
// depth for 'common.blocks' path is 1
// nested scheme should know how scan this directory
Scan only the button.css file
const config = require('bem-config')();
const walk = require('bem-walk');
const levelMap = config.levelMapSync();
walk('common.blocks/button/button.css', { levels: levelMap });
// depth for 'common.blocks' path is 2
// nested scheme should know how scan this file
I think better to just make a
stopmethod ...
This is exactly that feature what I need to developing plugin for search BEM-entities from the editor!