bigpipe / pagelet

Pagelets are small re-usable standalone components
MIT License
54 stars 6 forks source link

Call .initialize from constructor #10

Open Swaagie opened 10 years ago

Swaagie commented 10 years ago

Calling initialize by default (if available) would be a nice feature for standalone usability. It would also bring it closer in line with BackboneJS. The only problem is BigPipe currently relies on not calling initialize if the Pagelet is not authorized or disabled, see https://github.com/bigpipe/bigpipe/blob/master/page.js#L286-L290

jcrugzz commented 10 years ago

@Swaagie there could be some other flag to check im sure right? some post initializing that could be done for those cases?

Swaagie commented 10 years ago

sure but a developer could potentially include logic in initialize that is sensitive and should not be executed if the pagelet is disabled or unauthorized, but I'm sure we can think of a way that would do this in a sane manner

Swaagie commented 10 years ago

On a broader scope, functions like optimize and traverse have to be called as well each time if the pagelet is used outside bigpipe. Perhaps a small helper function called standalone (or similar) would be nice to have

Pagelet.standalone = function standalon() {
  var prototype = this.prototype;
  prototype.fragement = '{pagelet:template}' // unsure, but  will only render the template.

  return this.traverse().optimize();
}
Swaagie commented 10 years ago

Another thought, provide a plugin that adds standalone functionality to pagelets, that should keep the code clean and lean. Per example, rendering child pagelets is also an issue. Calling render on child pagelets from the parents render is not possible, as bigpipe would normally have pages iterating through the stack in parallel.

3rd-Eden commented 10 years ago

Why would optimize need to be called each time a pagelet is called outside of bigpipe? It only needs to be called once. And i'm +1 on adding a .standone method

Swaagie commented 10 years ago

with each time I ment, each time any pagelet is used outside bigpipe. In stead of just calling new Pagelet someone has to go through all the helper methods as well.