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

Add caching mech to bem-walk #44

Open
qfox opened this issue Apr 19, 2016 · 3 comments
Open

Add caching mech to bem-walk #44

qfox opened this issue Apr 19, 2016 · 3 comments

Comments

@qfox
Copy link
Contributor

qfox commented Apr 19, 2016

Some kind of storage class with simple interface (get/set/clean/clone/merge?).

@qfox qfox added the ready label Apr 19, 2016
@qfox
Copy link
Contributor Author

qfox commented Apr 19, 2016

Related #39

@blond blond removed the ready label Apr 30, 2016
@blond blond mentioned this issue May 10, 2016
@blond
Copy link
Member

blond commented May 10, 2016

API

I think API should look like this:

const config = require('bem-config')();
const walk = require('bem-walk');

const levelMap = config.levelMapSync();
const storage = new walk.Storage();

walk(['path/to/level'], {
    levels: levelMap,
    storage: storage
});

The Storage class should has get, set, and has methods.

const walk = require('bem-walk');
const storage = new walk.Storage();

storage.set('path/to/level', {
    'block': [
        {
            entity: 'block',
            tech: 'css',
            level: 'path/to/level',
            path: 'path/to/level/block/block.css'
        },
        {
            entity: 'block',
            tech: 'js',
            level: 'path/to/level',
            path: 'path/to/level/block/block.js'
        },
        /* ... */
    ]
});

const introspection = storage.get('path/to/level');

storage.has('path/to/level'); // true

Example:

Imagine that you need scan desktop.bundles/index and touch.bundles/index.

The first require common.blocks and desktop.blocks levels. The second require common.blocks and desktop.blocks levels.

In addition need scan lib/common.blocks for each bundle.

const config = require('bem-config')();
const walk = require('bem-walk');

const levelMap = config.levelMapSync();
const storage = new walk.Storage();

// Scan first bundle:
// the `lib/common.blocks`, `common.blocks` and `desktop.blocks` will be get from file system.
walk(['lib/common.blocks', 'common.blocks', 'desktop.blocks'], {
    levels: levelMap,
    storage: storage
});

// Scan second bundle:
// the `'lib/common.blocks` and `common.blocks` will be get from storage,
// the `touch.blocks` will be get from file system.
walk(['lib/common.blocks', 'common.blocks', 'touch.blocks'], {
    levels: config.levelMapSync(),
    storage: storage
});

// save `introspection` to file system
const introspection = storage.get('lib/common.blocks');
saveIntrospection(introspection); 

After we can load introspection:

const config = require('bem-config')();
const walk = require('bem-walk');

const levelMap = config.levelMapSync();
const storage = new walk.Storage();

// load `introspection` from file system
const introspection = loadIntrospection('lib/common.blocks');

storage.set('lib/common.blocks', introspection);

// Scan first bundle:
// the `lib/common.blocks` will be get from storage
// the `common.blocks` and `desktop.blocks` will be get from file system.
walk(['lib/common.blocks', 'common.blocks', 'desktop.blocks'], {
    levels: levelMap,
    storage: storage
});

// Scan second bundle:
// the `'lib/common.blocks` and `common.blocks` will be get from storage,
// the `touch.blocks` will be get from file system.
walk(['lib/common.blocks', 'common.blocks', 'touch.blocks'], {
    levels: config.levelMapSync(),
    storage: storage
});

Implementation

We can add storage walker and run it in core:

if (storage.has('path/to/level')) {
    storageWalker(level, add);
    callback();
} else {
    walk({ path: level, naming: naming }, add, callback);
}

@blond
Copy link
Member

blond commented May 17, 2016

Related #14

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

2 participants