Skip to content

refactor #3

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

refactor #3

wants to merge 5 commits into from

Conversation

tunnckoCore
Copy link

That's it. As commented.
cross-ref: base-repos/base-namespace#1, base-repos/base#12

only need misc stuff, code comments, readme and etc, i'll get to them later.

return name;

return function debug() {
var fn = require('debug');
Copy link

Choose a reason for hiding this comment

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

require('debug') should only be called once to avoid the logic inside require

Copy link
Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Author

Choose a reason for hiding this comment

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

Is lazy-cache do the job as I (we/you) expect?
Or this will also work? (it seems it work, but is really work? lol)

var fn = requiresCache.debug || (requiresCache.debug = require('debug'));

i'm not very familiar with caching and how to test it.

app.debug[ns] = debugFactory.call(app, ns);
app.debug[ns].color = app.debug.color;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to return plugin so that debug will be propagated down the "plugin tree". Let me do an illustration so this makes sense.. brb

Copy link
Author

Choose a reason for hiding this comment

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

Yea, okey.
It would be good to see some use-case / example, and i'll add a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

(this is for the templates docs, but it will help explain how plugins work in base. you obviously already know a lot about plugins, so this is for anyone who might find it useful)

Plugins

Overview of how Templates plugins work

App

The following example shows a plugin that will be invoked by the .use method. Example: app.use(plugin). When invoked, the plugin function is passed the application instance (app) as its only argument.

plugins-app

The plugin stops there and will not be called again, unless the plugin returns a function. If a function is returned it will be pushed onto the app.fns array and then called on each collection that is created using the app.create, app.collection, or app.list methods.

In the next example, a function is returned from the plugin so that it can be called again later.

Collection

plugins-collection

The plugin stops there and will not be called again, unless the plugin returns a function. If a function is returned it will be pushed onto the collection.fns array and then called on each view that is added to the collection.

In the next example, we'll return a function inside the collection plugin, so that it can be called again later.

View

plugins-view

End of the line...

Short-circuit: "smart plugins"

Don't like all the function nesting? Want to register your plugin with app but only have it run on specific objects? No problem, just short-circuit the plugin!

Every class has a boolean .is* property that is useful for checking the instance name. For example, the Templates class has an isTemplates property, view collections have isViews, and views have isView. (all "apps", like Templates, Assemble, Generate, etc. also have isApp as a convenience).

To make your plugins "smarter" and eliminate the nesting, try the following:

plugins-short-circuit

Generators

plugins-generators

Copy link
Author

Choose a reason for hiding this comment

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

Yea.. it's.. damn, you're not a human being, 😆
I was a bit familiar with it, but didn't realize it is so big and awesome, and that it can be so nested.
Great clarification.

Copy link
Contributor

Choose a reason for hiding this comment

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

haha, well it took me a while but I had to figure out how to use the diagram tool lol. glad you find it useful

but didn't realize it is so big and awesome

thanks! I just added a screen to show how plugins can be used with generators. this is only a high-level overview of part of the ecosystem. we still need to show verb, update, sub-generators, routes and middleware, and other parts of the build cycle.

it would be awesome if we could find a tool that makes it easy to create diagrams like these. most of the tools I've seen are for the browser or take a lot of work to create something that looks nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants