Khan / aphrodite

Framework-agnostic CSS-in-JS with support for server-side rendering, browser prefixing, and minimum CSS generation
5.34k stars 188 forks source link

Add public API to determine if an object is an aphrodite style or not #306

Open kevinbarabash opened 6 years ago

kevinbarabash commented 6 years ago

I'm working on some components that have a style prop that's similar to the style prop in React Native components which can take either inline styles or styles from StyleSheet objects. The components need to know how to disambiguate between the types of objects being passed in so that they can apply the slides correctly in the render method.

Proposed API:

function isAphroditeStyle(style: any) => boolean
lencioni commented 6 years ago

We do this in react-with-styles-interface-aphrodite. https://github.com/airbnb/react-with-styles-interface-aphrodite/blob/e9c088d8998bed347ff5c26f54a22d8dfd633cb6/src/utils/separateStyles.js

Can you make a case for adding it to this project vs a separate project or something?

kevinbarabash commented 6 years ago

If we change the internal implementation of Aphrodite it will break that code. It seems like a generally useful function to have to support tooling. We could do it in a separate package but that package should be part of this repo and have tests so in order to avoid breakages.

lencioni commented 6 years ago

Sure, might as well I guess. Want to submit a PR? It would be great if your PR refactored any internal code that might benefit to also use this function.

If I understand tree-shaking correctly, we should be able to expose this as a named export and it won't affect consumer bundle sizes if they don't import it.

kevinbarabash commented 6 years ago

If the function is use internally people will still get the code.