Conversation
e29a692 to
b555ba6
Compare
| const {sheets} = styled | ||
| const {staticSheet, dynamicSheet} = sheets | ||
|
|
||
| const classNames = new Set([ |
There was a problem hiding this comment.
Can we avoid Set? It needs a polyfil.
| [name]: composeClasses(staticSheet.classes[name], dynamicSheet.classes[name]), | ||
| }), {}) | ||
|
|
||
| return (...props: any) => createElement(InnerComponent, {sheets, classes, ...props}) |
There was a problem hiding this comment.
I would probably not inject sheets at all. What use cases are there anyways? Also in react-jss I inject sheet which refs to dynamicSheet if there is one and to static if there is no. Actually I did it because it was already there for the case people still using props.sheet. From my experience there should be no need to use sheet object in react.
There was a problem hiding this comment.
agree, I made it in relation to injectSheet, but it really doesn't look necessary
There was a problem hiding this comment.
If current sheet prop passing in react-jss makes troubles, we might want to remove it from there also.
| import composeClasses from './utils/compose-classes' | ||
| import type {styledType} from './types' | ||
|
|
||
| const injectStyled = (styled: styledType) => (InnerComponent: ReactClass<any>) => { |
| jest: true | ||
|
|
||
| globals: | ||
| ReactClass: true |
There was a problem hiding this comment.
Why is this needed, where do we use such a global?
There was a problem hiding this comment.
eslint consider flow types and it works with rules like 'no-undef`, but it dosnt about this flow type. so we need to add it as global.
but maybe there is better solution with some plugin etc., I'll take a look
| const createStyled = (jss?: Function = jssDefault) => (baseStyles: Object = {}) => { | ||
| let sheet | ||
| let dynamicSheet | ||
| const createStyled = (jss?: Function = jssDefault) => (baseStyles: Object = {}): styledType => { |
There was a problem hiding this comment.
styledType should be capitelized, no?
There was a problem hiding this comment.
Also lets use a type JssStyles = Object and type JssStyle = Object and put it into types, once we have a fully typed styles object for jss we can easily replace Object with the new one in types.
| } | ||
| export type StyledElementAttrsType = {tag: string, styles: Object} | ||
| export type StyledElementType = Function & StyledElementAttrsType | ||
| export type tagOrStyledElementTypeype = string | StyledElementType |
| const mountSheets = () => { | ||
| if (!sheets.staticSheet) { | ||
| sheets.staticSheet = jss.createStyleSheet(baseStyles, { | ||
| link: true, |
There was a problem hiding this comment.
why do you need link: true for static sheet?
719f977 to
fbbb43b
Compare
| padding: 10 | ||
| padding: 10, | ||
| '& + &': { | ||
| marginLeft; 10 |
| StyledType, | ||
| StyledElementAttrsType, | ||
| StyledElementType, | ||
| TagOrStyledElementTypeype, |
|
|
||
| static styles = elementStyles | ||
| static tag: string = tag | ||
| static styles: ComponentStylesType = elementStyles |
There was a problem hiding this comment.
just realized: elementStyles should be elementStyle, ownStyles should be ownStyle
| tagOrStyledElement: TagOrStyledElementTypeype, | ||
| ownStyles: ComponentStylesType | ||
| ): StyledElementType => { | ||
| const {tag, styles}: StyledElementAttrsType = typeof tagOrStyledElement === 'string' |
There was a problem hiding this comment.
Lets use tagName instead of tag everywhere, its more correct and aligned with element.tagName
| @@ -32,9 +51,8 @@ const createStyled = (jss?: Function = jssDefault) => (baseStyles: Object = {}) | |||
| const staticTag = `${tag}-${++counter}` | |||
There was a problem hiding this comment.
I would call it considered previous comment staticTagName
| sheets.staticSheet.addRule(staticTag, elementStyles) | ||
| } | ||
|
|
||
| if (dynamicStyles && !dynamicSheet.getRule(this.tagScoped)) { |
| ): StyledElementType => { | ||
| const {tag, styles}: StyledElementAttrsType = typeof tagOrStyledElement === 'string' | ||
| ? {tag: tagOrStyledElement, styles: {}} | ||
| const {tagName, style}: StyledElementAttrsType = typeof tagOrStyledElement === 'string' |
There was a problem hiding this comment.
tagOrStyledElement -> tagNameOrStyledElement
3de5ee1 to
35eac8b
Compare
| const sheets = {} | ||
| let counter = 0 | ||
|
|
||
| const getScopedTagName = (tagName: string) => `${tagName}-${++counter}` |
There was a problem hiding this comment.
we can actually move it to the utils and call it generateTagName, similar to jss https://github.com/cssinjs/jss/blob/master/src/utils/generateClassName.js
| if (dynamicStyles && !dynamicSheet.getRule(this.tagScoped)) { | ||
| dynamicSheet | ||
| if (dynamicStyle && !sheets.dynamicSheet.getRule(this.dynamicTagName)) { | ||
| sheets.dynamicSheet |
There was a problem hiding this comment.
just realized we don't need sheets object any more.
There was a problem hiding this comment.
we need, because we need mutated sheets here too https://github.com/cssinjs/styled-jss/pull/6/files#diff-f336995dd331140b2022485b207c9fc1R10
if we just export them, with reassign we will lost links to new sheets
There was a problem hiding this comment.
do we reassign them somewhere else than in mountSheets?? Should evtl mountSheets return them?
There was a problem hiding this comment.
no, you are right, we can just return them.
will fix it
| props: StyledElementPropsType | ||
|
|
||
| tagScoped = '' | ||
| dynamicTagName = '' |
There was a problem hiding this comment.
we could set dynamicTagName = generateTagName(tagName) here and remove constructor override, right?
There was a problem hiding this comment.
nope, cause we can call Components with different styles
<Button color="pink" />
<Button color="green" />and we need to have a scoped tagName for each instance
|
|
||
| componentWillUnmount() { | ||
| dynamicSheet.deleteRule(this.tagScoped) | ||
| sheets.dynamicSheet.deleteRule(this.dynamicTagName) |
There was a problem hiding this comment.
why do we remove the rule, we could reuse that rule next time the component mounts, no?
There was a problem hiding this comment.
because we generate new scoped name in constructor, so we can't get and old dynamicTagName for the pervious instance
There was a problem hiding this comment.
why? the instance will be reused in react ....
There was a problem hiding this comment.
right, but react will call constructor and we will lose it
There was a problem hiding this comment.
well, don't redefine it in this case if it is already defined?
| @@ -0,0 +1 @@ | |||
| export default (...args: any) => args.filter(Boolean).join(' ') | |||
There was a problem hiding this comment.
just realized, why do we use sometimes camel case and sometimes dash separated file names? In JSS I stick to camel case.
aafd1d4 to
0d79dbb
Compare
8ed9688 to
41a24aa
Compare
364d001 to
8a0a61d
Compare
Implement injectStyled from #4
@kof