-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't reiniting widget when callbacks change (#43)
refactoring fix unresolved dependencies refactor dialog add dummy tests
- Loading branch information
Showing
11 changed files
with
151 additions
and
50 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
|
||
import File from './file-select-callback' | ||
import Panel from './default-panel' | ||
|
||
const Example = ({ text, component: Component }) => ( | ||
<div> | ||
<h2>{text}</h2> | ||
|
||
<br /> | ||
<br /> | ||
|
||
<Component /> | ||
|
||
<hr /> | ||
</div> | ||
) | ||
|
||
const examples = [ | ||
{ | ||
text: 'rerendering on file select callback fire', | ||
component: File | ||
}, | ||
{ | ||
text: 'default panel example', | ||
component: Panel | ||
} | ||
] | ||
|
||
ReactDOM.render( | ||
examples.map((props, key) => <Example key={key} {...props} />), | ||
document.getElementById('root') | ||
) |
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,5 @@ | ||
import React from 'react' | ||
|
||
import { Panel } from '../src' | ||
|
||
export default () => <Panel publicKey='demopublickey' /> |
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,11 @@ | ||
import React, { useReducer } from 'react' | ||
|
||
import { Widget } from '../src' | ||
|
||
export default () => { | ||
const [, rerender] = useReducer(state => !state, false) | ||
|
||
const newFn = () => rerender() | ||
|
||
return <Widget publicKey='demopublickey' onFileSelect={newFn} /> | ||
} |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>D</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
|
||
<script src="./app.js"></script> | ||
</body> | ||
</html> |
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
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,12 @@ | ||
import { useEffect, useRef } from 'react' | ||
import isEqual from 'react-fast-compare' | ||
|
||
export const useDeepEffect = (effect, deps) => { | ||
const ref = useRef(undefined) | ||
|
||
if (!isEqual(deps, ref.current)) { | ||
ref.current = deps | ||
} | ||
|
||
useEffect(effect, ref.current) | ||
} |
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,31 @@ | ||
import { useRef } from 'react' | ||
import isEqual from 'react-fast-compare' | ||
|
||
export function useDeepMemo ( | ||
factory, | ||
deps | ||
) { | ||
let isValid = true | ||
|
||
const valueRef = useRef() | ||
// initial hook call | ||
if (!valueRef.current) { | ||
valueRef.current = { | ||
deps, | ||
result: factory() | ||
} | ||
// subsequent calls | ||
} else { | ||
isValid = !!( | ||
deps && | ||
valueRef.current.deps && | ||
isEqual(deps, valueRef.current.deps) | ||
) | ||
} | ||
|
||
const cache = isValid ? valueRef.current : { deps, result: factory() } | ||
// must update immediately so any sync renders here don't cause an infinite loop | ||
valueRef.current = cache | ||
|
||
return cache.result | ||
} |
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