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

Entities Mode #20

Open
blond opened this issue Feb 16, 2015 · 7 comments
Open

Entities Mode #20

blond opened this issue Feb 16, 2015 · 7 comments

Comments

@blond
Copy link
Member

blond commented Feb 16, 2015

The event will emit when will provide information on an entity with each file in each level.

Example of file system:

common.blocks/
└── button/
    ├── button.css   # (1)
    └── button.js    # (2)

desktop.blocks/
└── button/
    └── button.css   # (3) (4)

Run the following code:

var walk = require('bem-walk'),
    walker = walk(['common.blocks', 'desktop.blocks']);

walker.on('data', function (data) {
    console.log(data);
});

walker.on('entity', function (data) {
    console.log(data);
});

The result will be 4 events:

// event (1) on `data`
{
     entity: { block: 'button' },
     tech: 'css',
     level: 'common.blocks',
     path: 'common.blocks/button/button.css'
}
// event (2) on `data`
{
     entity: { block: 'button' },
     tech: 'js',
     level: 'common.blocks',
     path: 'common.blocks/button/button.js'
}
// event (3) on `data`
{
     entity: { block: 'button' },
     tech: 'css',
     level: 'desktop.blocks',
     path: 'desktop.blocks/button/button.css'
}
// event (4) on `entity`
{
    entity: { block: 'button' },
    levels: ['common.blocks', 'desktop.blocks'],
    techs: ['css']
    files: [
        {
            path: 'common.blocks/button/button.css',
            level: 'common.blocks',
            tech: 'css'
        },
        {
            path: 'desktop.blocks/button/button.css',
            level: 'desktop.blocks',
            tech: 'css'
        }
    ]
}
@tadatuta
Copy link
Member

is it going to fire all the entity events at once when walking is done?

@qfox
Copy link
Contributor

qfox commented Feb 16, 2015

@tadatuta Feels like this tactic would be the only possible for flat scheme. But for nested you'll got time lags between these events because there you can read dirs one by one and emit event on the end of reading directory instead of full scan.

@tadatuta
Copy link
Member

if I understood idea right, you can't emit until all the levels are checked

@qfox
Copy link
Contributor

qfox commented Feb 16, 2015

@tadatuta Actually, you can if you doing it right.

Let's assume you have these:

level1
  b1
  b2
  b3
level2
  b2
level3
  b3

You should read blocks in levels first, and then contents of blocks.
Read level1, level2, level3 first (and now you know which blocks you have in each level), and then read level1/*, level2/*, etc.

upd: actually, you can even tune your strategy here if some blocks can be quickly emitted (e.g. b1).

Simple.

Once again, this order doesn't mean anything for small projects/libraries. It means only for huge ones. But there are enough huge projects to start thinking about it imo.

@blond
Copy link
Member Author

blond commented May 9, 2016

Scheme can know when it scan files for depth.

common.blocks/      # level depth
  button/           # block depth
    button__text/   # elem depth
  input/
desktop.blocks/
  button/

It is mean that no need wait until all levels will be scanned.

Log example:

  1. common.blocks level has button and input blocks
  2. desktop.blocks level has button
  3. button entity part from common.blocks has been scanned, there's one more level
  4. input entity part from common.blocks has been scanned => emit info about input
  5. button entity part from desktop.blocks has been scanned => emit info about input
  6. button__text entity part from common.blocks has been scanned => emit info about button__text

@blond
Copy link
Member Author

blond commented May 10, 2016

For a start we can wait until all levels will be scaned and do optimization later.

@blond blond mentioned this issue May 10, 2016
@blond
Copy link
Member Author

blond commented May 10, 2016

Related #54

@blond blond changed the title Event entity Entities Mode May 10, 2016
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

4 participants