Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit d4ebab2

Browse files
committed
more issues with re-implementing the state on cached userPage views
1 parent 414a362 commit d4ebab2

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

js/router.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ module.exports = Backbone.Router.extend({
222222
options.viewArgs = options.viewArgs.length ? options.viewArgs : [options.viewArgs];
223223

224224
this.cleanup();
225+
window.obEventBus.trigger('setAddressBar', options.addressBarText);
225226

226227
$('body').attr('id', options.bodyID);
227228
$('body').attr('class', options.bodyClass);
@@ -267,22 +268,21 @@ module.exports = Backbone.Router.extend({
267268
this.$obContainer[0].scrollTop = this.view.__cachedScrollPos || 0;
268269
}
269270

270-
if (this.view.__cachedAddressBarText) {
271-
// ensure our address bar text reflects the state of the cached view
272-
window.obEventBus.trigger('setAddressBar', {'addressText': this.view.__cachedAddressBarText});
273-
} else {
274-
window.obEventBus.trigger('setAddressBar', options.addressBarText);
275-
}
271+
// if (this.view.__cachedAddressBarText) {
272+
// // ensure our address bar text reflects the state of the cached view
273+
// window.obEventBus.trigger('setAddressBar', {'addressText': this.view.__cachedAddressBarText});
274+
// } else {
275+
// window.obEventBus.trigger('setAddressBar', options.addressBarText);
276+
// }
276277

277278
this.trigger('cache-reattach', {
278279
view: this.view,
279-
requestedRoute: requestedRoute,
280-
cachedRoute: Backbone.history.getFragment()
280+
route: requestedRoute
281281
});
282282
} else {
283283
this.view = new (Function.prototype.bind.apply(View, [null].concat(options.viewArgs)));
284-
// clear address bar. Must happen after we set out view above.
285-
window.obEventBus.trigger('setAddressBar', options.addressBarText);
284+
// // clear address bar. Must happen after we set out view above.
285+
// window.obEventBus.trigger('setAddressBar', options.addressBarText);
286286
$('#content').html(this.view.$el);
287287
this.$obContainer[0].scrollTop = 0;
288288

js/views/homeVw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = pageVw.extend({
7676
},
7777

7878
onCacheReattach: function(e) {
79-
var splitRoute = e.requestedRoute.split('/'),
79+
var splitRoute = e.route.split('/'),
8080
searchText;
8181

8282
if (e.view !== this) return;

js/views/itemListVw.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
var __ = require('underscore'),
44
Backbone = require('backbone'),
5-
//$ = require('jquery'),
6-
//loadTemplate = require('../utils/loadTemplate'),
5+
baseVw = require('./baseVw'),
76
itemsShortCollection = require('../collections/itemsShortCl'),
87
itemShortView = require('./itemShortVw'),
98
simpleMessageView = require('./simpleMessageVw');
109

11-
module.exports = Backbone.View.extend({
10+
module.exports = baseVw.extend({
1211

1312
initialize: function(options){
1413
this.options = options || {};
@@ -18,8 +17,12 @@ module.exports = Backbone.View.extend({
1817
//this.listenTo(this.options.userModel, 'change', function(){
1918
// self.render();
2019
//});
21-
this.subViews = [];
22-
this.render();
20+
21+
// as of now, our base view doesn't support registerChild happening
22+
// before the view is fully initialized, hence the timeout here:
23+
setTimeout(() => {
24+
this.render();
25+
});
2326
},
2427

2528
render: function(){
@@ -42,24 +45,12 @@ module.exports = Backbone.View.extend({
4245
model: item,
4346
parentEl: this.$el
4447
});
45-
this.subViews.push(itemShort);
48+
// this.$el.append(itemShort.render().$el);
49+
this.registerChild(itemShort);
4650
},
4751

4852
renderNoneFound: function(){
4953
var simpleMessage = new simpleMessageView({title: this.options.title, message: this.options.message, el: this.$el});
50-
this.subViews.push(simpleMessage);
51-
},
52-
53-
close: function(){
54-
__.each(this.subViews, function(subView) {
55-
if (subView.close){
56-
subView.close();
57-
} else {
58-
subView.unbind();
59-
subView.remove();
60-
}
61-
});
62-
this.unbind();
63-
this.remove();
54+
this.registerChild(simpleMessage);
6455
}
6556
});

js/views/userPageVw.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,20 @@ UserPageVw = pageVw.extend({
331331
},
332332

333333
onCacheReattach: function(e) {
334+
var splitRoute = e.route.split('/'),
335+
state;
336+
334337
if (e.view !== this) return;
335338

336339
// todo: cache the million dom queries for #obContainer
337340
// use in this view
338341
$('#obContainer').on('scroll', this.onScroll);
339342
this.setCustomStyles();
343+
344+
if (splitRoute.length > 2 && splitRoute[2] !== this.state) {
345+
this.setState(splitRoute[2], splitRoute[3], { replaceState: true });
346+
}
347+
340348
},
341349

342350
onCacheDetach: function(e) {
@@ -474,6 +482,7 @@ UserPageVw = pageVw.extend({
474482
if (state === "listing"){
475483
//clear old templates
476484
this.$el.find('.js-list4').html("");
485+
this.tabClick(this.$el.find('.js-storeTab'), this.$el.find('.js-item'));
477486
this.renderItem(hash);
478487
$('#obContainer').scrollTop(352);
479488
} else if (state === "listingOld") {
@@ -991,7 +1000,6 @@ UserPageVw = pageVw.extend({
9911000
var self = this;
9921001
this.setItem(hash, function(model, response) {
9931002
if (response.vendor_offer){
994-
self.tabClick(self.$el.find('.js-storeTab'), self.$el.find('.js-item'));
9951003
self.loadingDeferred.resolve();
9961004
} else {
9971005
self.loadingDeferred.reject();

0 commit comments

Comments
 (0)