-
-
Notifications
You must be signed in to change notification settings - Fork 39
App Boilerplate: filters ? #6
Comments
Including the filter stuff in the base App gives people a good amount of power right out of the gate, but could make for a steeper learning curve if they don't know they have to do (or are intimidated by doing) Also, I can't really think of a situation where a plugin wouldn't at least need to register one filter to be useful (maybe later with platform plugins, then again those could also use filters). My Vote: include them, but we should provide examples that clearly show and educate about calling supers like |
👍 totally agree
This is a very interesting point that I hadn't thought about.
Anyway, I think it would be great if we could work around it somehow? A couple of ideas: Provide a 5th life-cycle function perhaps called init, which only the ghost-app boilerplates make use of, they know to call that function if they extend each other - Ghost core can be smart enough to run init, then activate. This is a reasonably simple solution but a bit dirty in terms of muddying the clear waters of the lifecycle. Change extend such that, if it finds an overridden lifecycle method, it wraps that method in another method which calls the method, and then calls the super. This is possible I think, it's a bit dirty in terms of being magical, but it does keep all the complexity in the extend method. Whaddyathink? |
We actually already have an initialize method that is called after the constructor and before any life cycle methods. We could go all java-like and expose things like App.prototype.activate = function () {
// register filters in filters: { ... }
return this.onActivate();
};
// No-op by default for onActivate
App.prototype.onActivate = function () { return; } Makes me feel kind of gross, but it would probably be the most straight forward way to provide extension without calling super. |
This is why I think an event-based pattern is better, users can add/remove listeners as they like, and they don't need to call
Another possibility is to use a middleware-style
But I think I prefer the first form, it feels more idiomatic, less boilerplate, more familiar to web devs. |
Our filters already behave like the first example you have, except they One other thing that filters allow is setting a priority, which I don't |
Okay @jgable sorry I was referring to the
We could even make this simpler by adding the following to the superclass:
This would allow us to simplify the plugin code to:
|
I think we want to have a promise chain, not events, so we can be sure when things are complete. |
Closes TryGhost#6 - Change extend helper to wrap life cycle events - Add filter registration to App base class
Closes TryGhost#6 - Change extend helper to wrap life cycle events - Add filter registration to App base class
Closes TryGhost#6 - Change extend helper to wrap life cycle events - Add filter registration to App base class
Another possible solution is to have Ghost manage calling the Ghost-app super method. i.e. if you have an app:
Ghost can do something like:
|
With #8, what we get is the ability to do the following:
I think this is super neat, and it's done so it doesn't interfere with the lifecycle. The only issue I have now is that it is also perfectly possible to do:
This breaks our 'one clear way to do something'. But I think that both syntaxes are useful. The simplified filter syntax is for basic apps that just want to do a thing with a filter. The advanced syntax means it is possible to register and unregister filters at specific times / in particular cases. Any thoughts? Next question is does the same syntax make sense for helpers? |
I don't think it's going to be possible to keep the advanced case from The helpers can be done in the same way. I have another class set up like |
Closes TryGhost#6 - Change extend helper to wrap life cycle events - Add filter registration to App base class
This is intended as a discussion point.
Should filters be baked into the app boilerplate?
https://github.com/jgable/ghost-plugin/blob/master/lib/FilterPlugin.js
The idea ends up being much like defining events in Backbone. It's definitely a pretty awesome dev experience, and it makes a lot of sense. It looks like:
The text was updated successfully, but these errors were encountered: