-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add plugins #75
base: master
Are you sure you want to change the base?
Add plugins #75
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty solid. I'm curious – can we test the unhappy path too? I would love to have to a good story around preventing poorly behaving plugins from completely breaking ui-box.
Did you have anything in mind? Only thing I can think of is testing that a plugin returns an object roughly in the shape that we expect. But I think the danger of a plugin system is that bad plugins can break ui-box, difficult to prevent that without severely limiting what they can do. |
@treygriffith if a plugin does not return |
@mshwery I added some handling for plugins that don't return something that at least looks like what we expect. In production, it skips the plugin and moves on. In all other environments it will throw. Let me know what you think of that approach. It obviously doesn't handle things that look valid but aren't (e.g. nonsense selectors like |
@mshwery any further thoughts on this PR? |
This change adds a new concept of Plugins to
ui-box
to enable arbitrary userland processing of selectors and styles.The plugin structure closely resembles that of glamor, which it was inspired by.
In the public API, this change exposes one new function:
usePlugin
.usePlugin
takes as its sole argument a function which should accept and return an object with aselector
property, containing the string selector for a given ruleset, and arules
property, containing an array of rules, each with aproperty
andvalue
.Plugins are executed in reverse from the order they are added (also from glamor). So if you add plugins
a
,b
, and thenc
, they will be executed asc->b->a
.The motivation for this change is #74. However, given that a plugin system may open up
ui-box
further than desired, I'm happy to open another PR which addresses #74 specifically without a generic plugin.