Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Не отменяется инициализация уничтоженных блоков #544

Closed
sameoldmadness opened this issue Sep 8, 2014 · 2 comments
Assignees

Comments

@sameoldmadness
Copy link
Contributor

  1. С помощью renderer.updateContent создаём внутри блока container блок outer
  2. Согласно BEMJSON внутри блока outer создаётся блок inner
  3. В конструкторе блока outer уничтожается блок inner
  4. В рамках afterCurrentEvents удалённый блок inner пытается инициализироваться и падает.

Псевдокод:

BEM.DOM.decl('container', {
    render: function () {
        var json = {
            block: 'outer',
            js: true
        };

        var bemjson = BEM.JSON.build(json);

        var html = BEMHTML.apply(bemjson);

        var $html = $(html);

        BEM.DOM.update(this, $html);
    }
});

BEM.JSON.decl('outer', {
    onBlock: function (ctx) {
        ctx.content({
            block: 'inner',
            js: true,
            mix: {
                block: 'outer',
                elem: 'inner'
            }
        });
    }
});

BEM.DOM.decl('outer', {
    onSetMod: {
        js: {
            inited: function () {
                BEM.DOM.destruct(this.elem('inner'));
            }
        }
    }
});

$('<div>').addClass('container').bem('container').render();

В итоге имеем невразумительную ошибку: Cannot read property '0' of undefined.

Ошибки можно избежать, используя afterCurrentEvent:

BEM.DOM.decl('outer', {
    onSetMod: {
        js: {
            inited: function () {
                this.afterCurrentEvent(function () {
                    BEM.DOM.destruct(this.elem('inner'));
                });
            }
        }
    }
});

Может, стоит при инициализации блока проверять, не уничтожен ли он?

@deeonis
Copy link
Contributor

deeonis commented Feb 25, 2015

@dfilatov что думаешь? Стоит ли нам это делать?

@sameoldmadness
Copy link
Contributor Author

Не получается воспроизвести на текущих версиях библиотек.

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

No branches or pull requests

3 participants