-
Notifications
You must be signed in to change notification settings - Fork 17
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
merge is one-level #5
Comments
Yeah so you expected a deep merge there, but got a shallow merge. |
Can be done. Do you like to send a pr? |
I haven't read the source code yet. |
Not sure though if I want a library for deep merge or just write own simpler version, because libraries handle tons of cases we don't have. |
@kof Will you accept PR for this using lodash.merge ? |
I am not sure its a good idea, in our case here we know what kind of objects we accept, its not as generic as lodash. I guess it will come with a big amount of utility functions and increase the build size a lot. |
Just installed lodash.merge, it comes with 2200LOC (16kb minified not gzipped), covering all the cases we don't have: array like objects, typed arrays, isPlainObject check (we always have plain object), arguments etc etc. |
https://www.npmjs.com/package/deep-assign and https://www.npmjs.com/package/deepmerge seem to be better options in our case, I would go for the first one, because I know @sindresorhus makes very high code quality. |
Btw. the version aphrodite uses is even smaller, because more specific to supported cases: https://github.com/Khan/aphrodite/blob/master/src/util.js#L40 |
Yes, lodash.merge it's pretty big. 60Kb function recursiveMerge(val1 = {}, val2 = {}) {
for (const key of Object.keys(val2)) {
if (val2.hasOwnProperty(key) {
val1[key] = (typeof val2[key] === "object" && val2[key] != null) ? recursiveMerge(val1[key], val2[key]) : val2[key];
}
}
return val1;
}
const finalStyle = rules.map(rule => rule.style).reduce(recurisveMerge, {}); |
Don't use |
@sindresorhus thanks for heads up, we have a very predictable use case here, not a generic one. We have only a need to support plain objects and arrays. Basically only JSON subset, no regexp, no arguments etc., what would you do? |
I think we should go for a custom merge for our case. |
@gutenye any updates? |
The discussion is very helpful. But I haven't started working on it (don't
have much time recently). You can close this issue if you want.
…On Mon, May 22, 2017 at 3:30 PM, Oleg Slobodskoi ***@***.***> wrote:
@gutenye <https://github.com/gutenye> any updates?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAXCyBvsKiO7Sq9HcjBvUnIa4khYs92Tks5r8Tl5gaJpZM4K7twQ>
.
--
JavaScript, Go, Linux and Open Source
- g <http://GutenYe.com>uten.me
- github.com/g <http://Github.com/GutenYe>utenye
|
I've published an alternative to this module: https://github.com/SamyPesse/aphrodite-to-jss that is more compatible with Aphrodite and supports the recursive merging. @kof I didn't wanted to do it as a PR on this module as it'd have been be a breaking change with the styles supported by If you think it makes sense to have those changes in |
aphrodite-jss is first of all a compatible adapter for aphrodite, so it should be as close as possible to what aphrodite does. I am not using aphrodite, so I am not aware of the details. I think we should release a major version if its a breaking change. |
The main differences we spotted when switching our code base to JSS (hundreds of components):
None of this is supported by I've done those changes in |
Can be added as part of aphrodite-jss transformation and converted to JSS format. Alternatively it could be implemented as a JSS plugin. I was thinking for quite some time about a good syntax for keyframes and we ended up with this in the latest v10 alpha. The reason we didn't go with aphridite's syntax is that semantically animationName is a name, but instead aphrodite expects the keyframes. |
Yes, & is syntax for nesting that also additionally supports pseudo selectors. We have a long standing issue to add a plugin for using pseudos without & cssinjs/jss#334 as a separate plugin, now with monorepo, adding plugins is easy, I think it should be also part of the default preset. |
Also a long standing issue, JSS vendor prefixer was always optimized for bundle size thats why we also went for feature detection at runtime, so it is currently incapable of server-side prefixing. I think we should add the missing parts for SSR to jss-plugin-vendor-prefixer or add inline-style-prefixer for SSR to it. cc @AleshaOleg (who was mainly focused on prefixer lately). |
How hard would be migrating from this syntax? JSS has a different fallbacks syntax, because we wanted to use arrays for multi-part values. |
Similar to keyframes, this can be implemented as part of the transformation or as a plugin. JSS went with this syntax, because of better semantics. Another thing: font-faces are used rarely, it is unlikely a problem to migrate, so not sure it is worth the effort. |
Yep, this can be done here. |
@SamyPesse I just made you admin of this repo and added you as owner of the npm package, so that I don't block you and you can update this package directly. |
Regarding the above changes in JSS repo, feel free to send a PR! |
Great, I like the JSS syntax, but having a safe migration path is better in our case.
Quite easy I think, I don't any part where we use it, it's mostly supported by Aphrodite because of But it can be handled by the prefixer plugin without being a global support.
This is done in
I agree, we don't use it, and this is the only Aphrodite syntax not supported in my module.
The tricky part with the merge is that it can cause issue with JSS plugin merge({
marginRight: 4
}, {
margin: 0
}); It should result in A basic merge implementation will result in I choose to go with a smart merge that result in Does it look like the right solution to you ? (it impacts the bundle size).
Yes, I'll see with my team to open PRs in the coming months.
Awesome thanks, I'll make a PR to refactor it once the compatibilities have been created as JSS plugins. Basically the following roadmap:
|
Reg. props-sort, I don't understand what the problem is, its fine if the final version is If the problem is current compatibility - user code relies on the ability to override all specific margins with margin for example, then I see 2 possible solutions:
If first one is not an option, second one seems reasonable. Especially if trying to keep the syntax closer to the aphrodite, you will want to remove some other plugins as well.
I would not do it, since the first 2 options exist, which don't make you maintain the properties. |
Note that animationName supporting the keyframes object would be a syntax specific to aphrodite-jss and should not be part of the JSS repo, it can be still implemented as a plugin inside of aphrodite-jss. |
I agree that But this is an issue in the merging (before the plugin enters in consideration): const styles = StyleSheet.create({
button: {
marginRight: 4
},
buttonNoMargin: {
margin: 0
}
})
function Button(props: { withMargin: boolean }) {
return <button className={css(styles.button, !props.withMargin && styles.buttonNoMargin)}>{props.children}</button>
} it should compiles to .button {
margin-right: 4;
}
.button-buttonNoMargin {
margin: 0;
} With the current implementation of .button {
margin-right: 4;
}
.button-buttonNoMargin {
margin: 0;
margin-right: 4;
} Solution 1: don't use
|
I get the problem now. I think the simplest would be to remove the sorting plugin and set the plugins up without preset. This way we keep the syntax to aphrodite's more closely and reduce the bundle size at the same time. But if you really want to do it with the smart marge - feel free. I consider this plugin more as a way to migrate. |
Given
Got
Expect
The text was updated successfully, but these errors were encountered: