first commit
This commit is contained in:
1
frontend/node_modules/rc-overflow/es/hooks/channelUpdate.d.ts
generated
vendored
Normal file
1
frontend/node_modules/rc-overflow/es/hooks/channelUpdate.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function channelUpdate(callback: VoidFunction): void;
|
||||
12
frontend/node_modules/rc-overflow/es/hooks/channelUpdate.js
generated
vendored
Normal file
12
frontend/node_modules/rc-overflow/es/hooks/channelUpdate.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import raf from "rc-util/es/raf";
|
||||
export default function channelUpdate(callback) {
|
||||
if (typeof MessageChannel === 'undefined') {
|
||||
raf(callback);
|
||||
} else {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.onmessage = function () {
|
||||
return callback();
|
||||
};
|
||||
channel.port2.postMessage(undefined);
|
||||
}
|
||||
}
|
||||
12
frontend/node_modules/rc-overflow/es/hooks/useEffectState.d.ts
generated
vendored
Normal file
12
frontend/node_modules/rc-overflow/es/hooks/useEffectState.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
type Updater<T> = T | ((origin: T) => T);
|
||||
type UpdateCallbackFunc = VoidFunction;
|
||||
type NotifyEffectUpdate = (callback: UpdateCallbackFunc) => void;
|
||||
/**
|
||||
* Batcher for record any `useEffectState` need update.
|
||||
*/
|
||||
export declare function useBatcher(): NotifyEffectUpdate;
|
||||
/**
|
||||
* Trigger state update by `useLayoutEffect` to save perf.
|
||||
*/
|
||||
export default function useEffectState<T extends string | number | object>(notifyEffectUpdate: NotifyEffectUpdate, defaultValue?: T): [T, (value: Updater<T>) => void];
|
||||
export {};
|
||||
48
frontend/node_modules/rc-overflow/es/hooks/useEffectState.js
generated
vendored
Normal file
48
frontend/node_modules/rc-overflow/es/hooks/useEffectState.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import useEvent from "rc-util/es/hooks/useEvent";
|
||||
import * as React from 'react';
|
||||
import { unstable_batchedUpdates } from 'react-dom';
|
||||
import channelUpdate from "./channelUpdate";
|
||||
/**
|
||||
* Batcher for record any `useEffectState` need update.
|
||||
*/
|
||||
export function useBatcher() {
|
||||
// Updater Trigger
|
||||
var updateFuncRef = React.useRef(null);
|
||||
|
||||
// Notify update
|
||||
var notifyEffectUpdate = function notifyEffectUpdate(callback) {
|
||||
if (!updateFuncRef.current) {
|
||||
updateFuncRef.current = [];
|
||||
channelUpdate(function () {
|
||||
unstable_batchedUpdates(function () {
|
||||
updateFuncRef.current.forEach(function (fn) {
|
||||
fn();
|
||||
});
|
||||
updateFuncRef.current = null;
|
||||
});
|
||||
});
|
||||
}
|
||||
updateFuncRef.current.push(callback);
|
||||
};
|
||||
return notifyEffectUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger state update by `useLayoutEffect` to save perf.
|
||||
*/
|
||||
export default function useEffectState(notifyEffectUpdate, defaultValue) {
|
||||
// Value
|
||||
var _React$useState = React.useState(defaultValue),
|
||||
_React$useState2 = _slicedToArray(_React$useState, 2),
|
||||
stateValue = _React$useState2[0],
|
||||
setStateValue = _React$useState2[1];
|
||||
|
||||
// Set State
|
||||
var setEffectVal = useEvent(function (nextValue) {
|
||||
notifyEffectUpdate(function () {
|
||||
setStateValue(nextValue);
|
||||
});
|
||||
});
|
||||
return [stateValue, setEffectVal];
|
||||
}
|
||||
Reference in New Issue
Block a user