-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
make rule-value-function and global work together #1427
base: master
Are you sure you want to change the base?
Conversation
I don't know how to add tests, but I think it would be a nice thing if someone has a bit of time! (also it looks that there are issues in master that prevent the tests from running) |
See #1335 (comment) regarding the syntax. |
// It is a rules container like for e.g. ConditionalRule. | ||
if (rule.rules instanceof RuleList) { | ||
// Ignore if there is an updateFun | ||
if (!hasUpdateFun && rule.rules instanceof RuleList) { |
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.
breaks encapsulation between plugins and the core, core has no knowledge about style functions, so far we managed to run the plugin in a way that doesn't require this
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.
the idea is that the plugin reacts to onUpdate hook and calls the function
@@ -22,7 +23,19 @@ export default function functionPlugin() { | |||
onCreateRule(name?: string, decl: JssStyle, options: RuleOptions): Rule | null { | |||
if (typeof decl !== 'function') return null | |||
const rule: StyleRuleWithRuleFunction = (createRule(name, {}, options): any) | |||
rule[fnRuleNs] = decl |
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 was how we hide the implementation detail of the interface that only this plugin knows how to handle
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.
Hey, thanks for the PR, we def. need to change the implementation
Would be great if someone added tests to rule-value-function package, so we can play with the implementation details and find a better way |
Fix #1335
Implementation details
I attach an attribute
updateFun
to rules with type'global'
that have a function as declaration (i.e. rules that match both plugins).I already had to modify
RuleList.js
to prevent the special caserule.rules instanceof RuleList
from skipping the update, so I included the code that executesupdateFun
inRuleList.js
. An important choice (that is easily modifiable) is thatplugins.onUpdate
will not be launched on the global rule that is updated with a function: other plugins will not run on the updated properties.Another meaningful possibility would be to include the call to
updateFun
in theonUpdate
method of therule-value-function
. This would allow us to callplugins.onUpdate
fromRuleList.js
, so have other plugins run on the rule after update. I was not sure what interactions this could create with other plugins so I didn't handle it this way.It is my first contribution to a JS project, so please feel free to give me advice to improve my coding style 😃
Example
gives