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

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

Open
qfox opened this issue Feb 5, 2015 · 17 comments
Open

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

qfox opened this issue Feb 5, 2015 · 17 comments

Comments

@qfox
Copy link
Contributor

qfox commented Feb 5, 2015

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

@blond
Copy link
Member

blond commented Feb 15, 2015

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

@eGavr
Copy link
Contributor

eGavr commented Feb 15, 2015

👍 👍 👍

@qfox
Copy link
Contributor Author

qfox commented Feb 15, 2015

Okay, let's move to #16 then.

@qfox qfox closed this as completed Feb 15, 2015
@blond
Copy link
Member

blond commented Feb 15, 2015

@zxqfox, it's a different issues ;)

@blond blond reopened this Feb 15, 2015
@blond
Copy link
Member

blond commented Feb 15, 2015

👍 👍 👍

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

@eGavr
Copy link
Contributor

eGavr commented Feb 15, 2015

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

@qfox
Copy link
Contributor Author

qfox commented Feb 15, 2015

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

@blond
Copy link
Member

blond commented Feb 16, 2015

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

@qfox
Copy link
Contributor Author

qfox commented Feb 16, 2015

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

@tadatuta
Copy link
Member

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

@qfox
Copy link
Contributor Author

qfox commented Feb 16, 2015

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
Copy link
Contributor Author

qfox commented Feb 16, 2015

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

@tadatuta
Copy link
Member

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

@qfox
Copy link
Contributor Author

qfox commented Feb 16, 2015

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

I can't get what for?

@tadatuta
Copy link
Member

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

@blond
Copy link
Member

blond commented May 10, 2016

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

@tenorok
Copy link

tenorok commented Mar 1, 2017

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants