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

[react-jss] Hooks #1089

Merged
merged 61 commits into from
Jun 7, 2019
Merged
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
1b3fade
Revert "Revert "Add dynamic rules to static sheet""
Mar 2, 2019
5dbc7dc
Fix adding dynamic rules to sheet
Mar 2, 2019
0768cae
Fix a few tests
Mar 2, 2019
d017126
Fix tests
Mar 2, 2019
85cec4e
Format code
Mar 2, 2019
91f6882
Add comments
Mar 6, 2019
b507aae
Merge branch 'master' into feat/move-dynamic-rules-into-static-sheet
Mar 10, 2019
61d465e
Merge branch 'master' into feat/move-dynamic-rules-into-static-sheet
Mar 10, 2019
2ca10eb
Update changelog
Mar 10, 2019
45215c6
Update size-snapshot
Mar 10, 2019
48f899d
Initial draft
Mar 10, 2019
b8284c0
Initial version of hook
Mar 15, 2019
7769334
Add missing dependency
Apr 13, 2019
8fed824
Fix some type issues
Apr 14, 2019
11b0fcf
Rename hook folder to create-use-styles and hoc to with-styles
Apr 14, 2019
b20f7ea
Unify some files
Apr 14, 2019
ae88758
Fix imports
Apr 14, 2019
cf23380
Fix some flow issues
Apr 14, 2019
d9b8452
Update size snapshots
Apr 14, 2019
cbef52d
Fix some eslint problems
Apr 14, 2019
9ee1369
Merge branch 'master' into react-jss/feature/hooks
Apr 14, 2019
ad05c90
Update packages/react-jss/src/create-use-styles.js
eps1lon Apr 15, 2019
ae7841a
Update file names and default exports
Apr 15, 2019
800a929
Use type instead of interface
Apr 15, 2019
4967ece
Fix linting
Apr 15, 2019
b49de75
Fixed PR comments
Apr 15, 2019
50725d3
Update size snapshots
Apr 20, 2019
8fcc455
fix linter, make all file names camel cased
kof Apr 23, 2019
01c0f54
Use state instead of relying on memo
May 4, 2019
76fa59a
Merge remote-tracking branch 'origin/react-jss/feature/hooks' into re…
May 4, 2019
02b641c
Use is-in-browser package
May 4, 2019
8a185ab
Fix some type issues and add support for recreating the sheet when th…
May 5, 2019
8b78a2b
Merge branch 'master' into react-jss/feature/hooks
kof May 6, 2019
7e2a92e
upgrade theming
kof May 7, 2019
b08cd37
add sheet to the registry when managing sheets, pass a theme when usi…
kof May 10, 2019
2036cf4
Fixed all tests
May 30, 2019
5aed3f8
Fix linting etc.
May 30, 2019
d4d372a
Use MIN_SAFE_INTEGER
May 30, 2019
965850b
Merge branch 'master' into react-jss/feature/hooks
kof Jun 2, 2019
afa04d8
remove the need for extra eslit rules
kof Jun 2, 2019
f6a9af4
Add tests for hooks and fix some issue
Jun 2, 2019
59e5a2c
Remove check for disableStylesGeneration
Jun 2, 2019
4f17fea
more explicit name for the hook
kof Jun 5, 2019
71b53e6
port class name prefix test
kof Jun 5, 2019
59c2560
reuse tests between hooks and hocs
kof Jun 5, 2019
aef6158
make dynamicStyles tests use hooks
kof Jun 5, 2019
32bb698
generate dynamic styles test using HOC
kof Jun 5, 2019
12b151c
migrate all dynamic styles tests to use createStyledComponent
kof Jun 5, 2019
62252f1
refactor theming tests
kof Jun 5, 2019
73964b6
Rewrite to useReducer
Jun 6, 2019
3dc8d2e
Fix JssProvider
Jun 6, 2019
e46bde6
port theming tests for hooks
kof Jun 6, 2019
af178af
Merge branch 'react-jss/feature/hooks' of github.com:cssinjs/jss into…
kof Jun 6, 2019
76d0964
move reducer to the module scope, since it doesn't need to be recreated
kof Jun 6, 2019
07322b5
Merge branch 'master' into react-jss/feature/hooks
kof Jun 7, 2019
1fd87da
reset module Id
kof Jun 7, 2019
11725ec
rename shallow-equal, add a note
kof Jun 7, 2019
86e5742
hooks docs
kof Jun 7, 2019
5b0af83
better description
kof Jun 7, 2019
95bef20
better wording
kof Jun 7, 2019
68bbae3
fix link
kof Jun 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move reducer to the module scope, since it doesn't need to be recreated
kof committed Jun 6, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 76d096471ed153629253db7d0b226574393ef0b5
24 changes: 12 additions & 12 deletions packages/react-jss/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dist/react-jss.js": {
"bundled": 128529,
"minified": 44367,
"gzipped": 13869
"bundled": 128542,
"minified": 44373,
"gzipped": 13874
},
"dist/react-jss.min.js": {
"bundled": 96142,
"minified": 34474,
"gzipped": 11084
"bundled": 96155,
"minified": 34480,
"gzipped": 11091
},
"dist/react-jss.cjs.js": {
"bundled": 20982,
"minified": 9838,
"gzipped": 3185
"bundled": 20993,
"minified": 9854,
"gzipped": 3193
},
"dist/react-jss.esm.js": {
"bundled": 20131,
"minified": 9097,
"gzipped": 3064,
"bundled": 20142,
"minified": 9113,
"gzipped": 3072,
"treeshaked": {
"rollup": {
"code": 2040,
55 changes: 26 additions & 29 deletions packages/react-jss/src/createUseStyles.js
Original file line number Diff line number Diff line change
@@ -20,6 +20,13 @@ const useEffectOrLayoutEffect = isInBrowser ? React.useLayoutEffect : React.useE

const noTheme = {}

const reducer = (prevState, action) => {
if (action.type === 'updateSheet') {
return action.payload
}
return prevState
}

const createUseStyles = <Theme: {}>(styles: Styles<Theme>, options?: HookOptions<Theme> = {}) => {
const {index = getSheetIndex(), theming, name = 'Hook', ...sheetOptions} = options
const ThemeContext = (theming && theming.context) || DefaultThemeContext
@@ -35,38 +42,28 @@ const createUseStyles = <Theme: {}>(styles: Styles<Theme>, options?: HookOptions
const context = React.useContext(JssContext)
const theme = useTheme()

const [state, dispatch] = React.useReducer(
(prevState, action) => {
if (action.type === 'updateSheet') {
return action.payload
}

return prevState
},
null,
() => {
const sheet = createStaticSheet({
context,
styles,
name,
theme,
index,
sheetOptions
})

if (context.registry && sheet) {
context.registry.add(sheet)
}
const [state, dispatch] = React.useReducer(reducer, null, () => {
const sheet = createStaticSheet({
context,
styles,
name,
theme,
index,
sheetOptions
})

if (context.registry && sheet) {
context.registry.add(sheet)
}

const dynamicRules = sheet && addDynamicRules(sheet, data)
const dynamicRules = sheet && addDynamicRules(sheet, data)

return {
sheet,
dynamicRules,
classes: sheet ? getSheetClasses(sheet, dynamicRules) : {}
}
return {
sheet,
dynamicRules,
classes: sheet ? getSheetClasses(sheet, dynamicRules) : {}
}
)
})

useEffectOrLayoutEffect(
() => {