forked from rowyio/rowy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rowyio#1158 from rowyio/develop
Develop
- Loading branch information
Showing
12 changed files
with
198 additions
and
63 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
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,29 @@ | ||
import { | ||
MutableRefObject, | ||
useCallback, | ||
useRef, | ||
useSyncExternalStore, | ||
} from "react"; | ||
|
||
// NOTE: This is not the final solution. But is a potential solution for this problem. | ||
export default function useStateWithRef<T>( | ||
initialState: T | ||
): [T, (newValue: T) => void, MutableRefObject<T>] { | ||
const value = useRef<T>(initialState); | ||
const get = useCallback(() => value.current, []); | ||
const subscribers = useRef(new Set<() => void>()); | ||
|
||
const set = useCallback((newValue: T) => { | ||
value.current = newValue; | ||
subscribers.current.forEach((callback) => callback()); | ||
}, []); | ||
|
||
const subscribe = useCallback((callback: () => void) => { | ||
subscribers.current.add(callback); | ||
return () => subscribers.current.delete(callback); | ||
}, []); | ||
|
||
const state = useSyncExternalStore(subscribe, get); | ||
|
||
return [state, set, value]; | ||
} |
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,22 @@ | ||
import { useEffect, useRef } from "react"; | ||
|
||
// This hook is used to log changes to props in a component. | ||
export default function useTraceUpdates( | ||
props: { [key: string]: any }, | ||
printMessage: string = "Changed props:" | ||
) { | ||
const prev = useRef(props); | ||
useEffect(() => { | ||
const changedProps = Object.entries(props).reduce((ps, [k, v]) => { | ||
if (prev.current[k] !== v) { | ||
// @ts-ignore | ||
ps[k] = [prev.current[k], v]; | ||
} | ||
return ps; | ||
}, {}); | ||
if (Object.keys(changedProps).length > 0) { | ||
console.log(printMessage, changedProps); | ||
} | ||
prev.current = props; | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
type RowRef = Pick<FirebaseFirestore.DocumentReference, "id", "path">; | ||
type RowRef<T> = { id: string; path: string; parent: T }; | ||
interface Ref extends RowRef<Ref> {} | ||
|
||
type FormulaContext = { | ||
row: Row; | ||
ref: RowRef; | ||
// storage: firebasestorage.Storage; | ||
// db: FirebaseFirestore.Firestore; | ||
ref: Ref; | ||
}; | ||
|
||
type Formula = (context: FormulaContext) => "PLACEHOLDER_OUTPUT_TYPE"; |
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
Oops, something went wrong.