Skip to content

Fix-649 #650

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ns.update.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@
this.view._getUpdateTree(tree);
}

if (tree.__hasInvalidModels__) {
this.abort();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сломалось где-то 5 тестов.
К примеру, тут https://github.com/yandex-ui/noscript/blob/master/test/spec/ns.update.edge-cases.js#L228

Похоже, прямо весь ns.Update отменять из-за одного вида, у которого invalid модель - не самая лучшая идея.

@vitkarpov


this.log('created render tree', tree);
this.stopTimer('collectViews');

Expand Down
14 changes: 13 additions & 1 deletion src/ns.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,12 @@
*/
ns.View.prototype._getUpdateTree = function(tree) {
if ( !this.isValid() ) {
tree.views[this.id] = this._getViewTree();
var viewTree = this._getViewTree();
if (viewTree.models.__hasInvalidModels__) {
delete viewTree.models.__hasInvalidModels__;
tree.__hasInvalidModels__ = true;
}
tree.views[this.id] = viewTree;
} else {
this._apply(function(view) {
view._getUpdateTree(tree);
Expand Down Expand Up @@ -1047,6 +1052,13 @@
// structure for convenient matching
modelsData[id][id] = model.getData();
} else {
// Special case - some of the models was invalidated - if it was during ns.Update - it will be aborted.
// @see #649
if (model.status === 'invalid') {
// Special property - will be deleted in caller method _getUpdateTree.
modelsData.__hasInvalidModels__ = true;
}

// insuccessful model status
modelsData[id].status = 'error';
// structure for convenient matching
Expand Down
78 changes: 78 additions & 0 deletions test/spec/ns.update.edge-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,82 @@ describe('ns.Update. Синтетические случаи', function() {
expect(ns.request.models).to.have.callCount(0);
});
});

xdescribe('Если на момент обновления DOM-а одна из моделей в status=invalid => ns.Update должен абортиться =>', function() {
beforeEach(function() {
ns.Model.define('m1');
ns.Model.get('m1').setData({});

ns.View.define('app');
ns.View.define('v1', { models: [ 'm1' ] });

ns.layout.define('app', {
'app': {
'v1': {}
}
});

this.sinon.server.autoRespond = true;
this.sinon.server.respond(function(xhr) {
xhr.respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({
models: [
{ data: true }
]
})
);
});

this.view = ns.View.create('app');
this.layout = ns.layout.page('app');

this.firstUpdateDone = this.sinon.spy();

return new ns.Update(this.view, this.layout, {}).render()
.then(this.firstUpdateDone);
});

it('первый ns.Update успешно выполняется', function() {
expect(this.firstUpdateDone).to.have.callCount(1);
});

describe('после запроса моделей кто-то успевает вызвать invalidate у модели m1 =>', function() {
beforeEach(function() {
var origRequestAllModels = ns.Update.prototype._requestAllModels;
ns.Update.prototype._requestAllModels = function() {
var resultPromise = origRequestAllModels.apply(this, arguments);
resultPromise.then(function() {
ns.Model.get('m1').invalidate();
});
return resultPromise;
};

this.update = new ns.Update(this.view, this.layout, {});
});

it('второй ns.Update не должен завершиться', function(finish) {
this.update.render()
.then(function() {
finish('second ns.Update should not resolve');
}, function(result) {
try {
expect(result.error).to.be.equal(ns.U.STATUS.EXPIRED);
finish();
} catch(e) {
finish(e);
}
});
})

// it('', function() {
// expect(this.secondUpdateDone).to.have.callCount(0);
// });

// it('у второго ns.Update должен вызваться abort', function() {
// expect(this.update.abort).to.have.callCount(1);
// });
});
});
});