lazojs / lazo

A client-server web framework built on Node.js that allows front-end developers to easily create a 100% SEO compliant, component MVC structured web application with an optimized first page load.
MIT License
366 stars 48 forks source link

Client side collection binding bug #279

Open adam-26 opened 9 years ago

adam-26 commented 9 years ago

Steps to reproduce:

  1. Request initial page from server that renders a collection view, where the collection is empty
  2. Once loaded in the client browser, add an item to the collection

Bugs: After step 1, the 'EmptyItemView' has a state of detached After step 2, the new 'ItemView' has a state of detached and neither 'attach()' nor 'afterRender()' are executed for the new view. I believe adding the EmptyItemView has the same problems.

If you paste the following code block into lib/public/views/collection.js it will resolve problem 2.

    _addItemView: function (model, collection, options) {
            var self = this;
            flexo.CollectionView.prototype._addItemView.call(self, model, collection, {
                success: function(view) {
                    var $el = collection.length ? self._getViewEl(model) : self._getCollectionTarget(collection);
                    view.attach($el[0], {
                        error: options.error,
                        success: function () {
                            view.afterRender();
                            if (options.success) {
                                options.success(view);
                            }
                        }
                    });
                },
                error: options.error
            });
        }

I'm not sure what the best way to resolve these issues are, I have only had time to identify the cause for now and the code above is just something I quickly threw together.

Adam.