bem-walk icon indicating copy to clipboard operation
bem-walk copied to clipboard

Ability to read just some part of level instead of full walk

Open qfox opened this issue 10 years ago • 17 comments
trafficstars

Is this the same as "Ability to stop walking at some point"?

qfox avatar Feb 05 '15 16:02 qfox

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

blond avatar Feb 15 '15 00:02 blond

:+1: :+1: :+1:

eGavr avatar Feb 15 '15 09:02 eGavr

Okay, let's move to #16 then.

qfox avatar Feb 15 '15 10:02 qfox

@zxqfox, it's a different issues ;)

blond avatar Feb 15 '15 10:02 blond

:+1: :+1: :+1:

А у Жеки 3 руки! ))

blond avatar Feb 15 '15 10:02 blond

Это я просто очень рад ;)

eGavr avatar Feb 15 '15 10:02 eGavr

@andrewblond If you've made #16 this task will go higher to builder or level-configurator. What's for we need it in walker?

qfox avatar Feb 15 '15 10:02 qfox

@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.

blond avatar Feb 16 '15 09:02 blond

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

qfox avatar Feb 16 '15 21:02 qfox

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')

tadatuta avatar Feb 16 '15 21:02 tadatuta

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?

qfox avatar Feb 16 '15 21:02 qfox

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

qfox avatar Feb 16 '15 21:02 qfox

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 :)

tadatuta avatar Feb 16 '15 21:02 tadatuta

to get just all techs of current block and its elements and mods

I can't get what for?

qfox avatar Feb 16 '15 21:02 qfox

e.g. to provide block info on bem.info

tadatuta avatar Feb 17 '15 08:02 tadatuta

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

blond avatar May 10 '16 20:05 blond

I think better to just make a stop method ...

This is exactly that feature what I need to developing plugin for search BEM-entities from the editor!

tenorok avatar Mar 01 '17 20:03 tenorok