-
Notifications
You must be signed in to change notification settings - Fork 65
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
Initial hooks implementation #159
Open
ethul
wants to merge
17
commits into
main
Choose a base branch
from
hooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
90e61f0
Initial hooks implementation
ethul 0e5d81b
Remove Action type
ethul 1088218
Fix remove Action
ethul 53d8011
Flip createElementHooks arguments
ethul 102d044
Remove re-export
ethul a60a253
Use Hook type
ethul e29447e
Export createElementHooks
ethul e39a96c
Rename Hooks to Hook
ethul 140c3bc
Use Effect
ethul 4e456da
Updates based on feedback from @natefaubion
ethul 2c1a2cc
Fix createHookLeafElement
ethul 088d175
Update unsafeCreateHookLeafElement
ethul 7b5ec57
Update useMemo
ethul e8b5738
Fix dispatch
ethul edcd569
Refactor Context
ethul ba17b83
Add createRenderPropsElement context consumer creation
ethul ebe5f47
Refactor Refs
ethul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
'use strict'; | ||
|
||
var React = require('react'); | ||
|
||
exports.useState_ = function useState_(Tuple, initialState) { | ||
var result = React.useState(initialState); | ||
|
||
var state = result[0]; | ||
|
||
var setState = result[1]; | ||
|
||
var tuple = Tuple(state)(setState); | ||
|
||
return tuple; | ||
}; | ||
|
||
exports.useEffect_ = function useEffect_(effect, inputs) { | ||
var result = inputs ? React.useEffect(effect, inputs) : React.useEffect(effect); | ||
|
||
return result; | ||
}; | ||
|
||
exports.useContext_ = function useContext_(context) { | ||
var result = React.useContext(context); | ||
|
||
return result; | ||
} | ||
|
||
exports.useReducer_ = function useReducer_(Tuple, reducer, initialState) { | ||
var result = React.useReducer(reducer, initialState); | ||
|
||
var state = result[0]; | ||
|
||
var dispatch = result[1]; | ||
|
||
var tuple = Tuple(state)(dispatch); | ||
|
||
return tuple; | ||
}; | ||
|
||
exports.useReducerLazy_ = function useReducerLazy_(Tuple, reducer, initialState, initialAction) { | ||
var result = React.useReducer(reducer, initialState, initialAction); | ||
|
||
var state = result[0]; | ||
|
||
var dispatch = result[1]; | ||
|
||
var tuple = Tuple(state)(dispatch); | ||
|
||
return tuple; | ||
}; | ||
|
||
exports.useCallback_ = function useCallback_(callback, inputs) { | ||
var result = inputs ? React.useCallback(callback, inputs) : React.useCallback(callback); | ||
|
||
return result; | ||
}; | ||
|
||
exports.useMemo_ = function useMemo_(memo, inputs) { | ||
var result = inputs ? React.useMemo(memo, inputs) : React.useMemo(memo); | ||
|
||
return result; | ||
}; | ||
|
||
exports.useRef_ = function useRef_(initialValue) { | ||
var result = React.useRef(initialValue); | ||
|
||
return result; | ||
} | ||
|
||
exports.getRef_ = function getRef_(ref) { | ||
return ref.current; | ||
} | ||
|
||
exports.setRef_ = function setRef_(ref, value) { | ||
ref.current = value; | ||
} | ||
|
||
exports.useImperativeMethods_ = function useImperativeMethods_(ref, imperativeMethods, inputs) { | ||
var result = inputs ? React.useImperativeMethods(ref, imperativeMethods, inputs) : React.useImperativeMethods(ref, imperativeMethods); | ||
|
||
return result; | ||
}; | ||
|
||
exports.useMutationEffect_ = function useMutationEffect_(mutationEffect, inputs) { | ||
var result = inputs ? React.useMutationEffect(mutationEffect, inputs) : React.useMutationEffect(mutationEffect); | ||
|
||
return result; | ||
}; | ||
|
||
exports.useLayoutEffect_ = function useLayoutEffect_(layoutEffect, inputs) { | ||
var result = inputs ? React.useLayoutEffect(layoutEffect, inputs) : React.useLayoutEffect(layoutEffect); | ||
|
||
return result; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createHookElement
likecreateLeafElement
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this all uses
createElement
under the hood, this isn't parametric due tokey
andref
props.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good for
createHookElement
. Noted onkey
andref
.