Skip to content
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

Optional default property #149

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

Conversation

scottmas
Copy link

For those of us coming from a React Native background, having to specify a "default" property on declarations where we don't have any active names is like nails on chalkboard. This is a backwards compatible tweak that makes specifying the "default" property optional when no activeNames are specified. Basically, it allows this:

import ReactCSS from 'reactcss'

const styleObj = {
   logo: {
     color: 'blue'
   },
   header: {
      backgroundColor: 'black'
   } 
}

const styles = ReactCSS(styleObj)

console.log(
  _.isEqual(styleObj, styles) // outputs true
) 

This is far more ergonomic for my use case in which I plan to basically never use activeNames.

Are you okay with this change? It is backwards compatible, but would you prefer maybe a separate named export to expose this functionality? That would also work.

For those of us coming from a React Native background, having to specify a "default" property on every single style declaration is a little like nails on chalkboard. If the user is not specifying any activeNames, it's also completely redundant. Without it, the syntax is almost identical to React Native:

```javascript
import { StyleSheet } from 'react-native' // Basically the sames as `import reactcss from "reactcss"`

const styles = StyleSheet.create({ // Basically the same as `reactcss({...})`
  card: {
     backgroundColor: 'red'
  }
})
```

This is admittedly a syntactic nicety, but it completely backwards compatible and would just be an optional function signature.
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.

1 participant