Skip to content

Commit

Permalink
Merge branch 'react-component:master' into preact-supportRef-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaNb4 authored Dec 13, 2023
2 parents ef55808 + da5cdae commit 21bd73a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-util",
"version": "5.38.0",
"version": "5.38.1",
"description": "Common Utils For React Component",
"keywords": [
"react",
Expand Down Expand Up @@ -43,7 +43,7 @@
},
"devDependencies": {
"@rc-component/father-plugin": "1.0.0",
"@testing-library/react": "^13.0.0",
"@testing-library/react": "^14.1.2",
"@types/jest": "^29.4.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
Expand All @@ -53,16 +53,18 @@
"create-react-class": "^15.6.3",
"cross-env": "^7.0.2",
"dumi": "^2.1.3",
"eslint": "~7.32.0",
"eslint": "^8.54.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-unicorn": "^49.0.0",
"father": "^4.1.3",
"glob": "^9.2.1",
"husky": "^8.0.3",
"lint-staged": "^13.1.2",
"np": "^7.6.3",
"lint-staged": "^15.1.0",
"np": "^9.0.0",
"rc-test": "^7.0.14",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"typescript": "^4.1.3"
"typescript": "^5.3.2"
},
"peerDependencies": {
"react": ">=16.9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/composeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function composeProps<T extends Record<string, any>>(
};
}
});
return composedProps;
return composedProps as T;
}

export default composeProps;
6 changes: 5 additions & 1 deletion src/raf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ const wrapperRaf = (callback: () => void, times = 1): number => {

wrapperRaf.cancel = (id: number) => {
const realId = rafIds.get(id);
cleanup(realId);
cleanup(id);
return caf(realId);
};

if (process.env.NODE_ENV !== 'production') {
wrapperRaf.ids = () => rafIds;
}

export default wrapperRaf;
17 changes: 14 additions & 3 deletions src/warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ export const preMessage = (fn: preMessageFn) => {
preWarningFns.push(fn);
};

/**
* Warning if condition not match.
* @param valid Condition
* @param message Warning message
* @example
* ```js
* warning(false, 'some error'); // print some error
* warning(true, 'some error'); // print nothing
* warning(1 === 2, 'some error'); // print some error
* ```
*/
export function warning(valid: boolean, message: string) {
// Support uglify
if (
process.env.NODE_ENV !== 'production' &&
!valid &&
Expand All @@ -34,8 +44,8 @@ export function warning(valid: boolean, message: string) {
}
}

/** @see Similar to {@link warning} */
export function note(valid: boolean, message: string) {
// Support uglify
if (
process.env.NODE_ENV !== 'production' &&
!valid &&
Expand Down Expand Up @@ -67,10 +77,12 @@ export function call(
}
}

/** @see Same as {@link warning}, but only warn once for the same message */
export function warningOnce(valid: boolean, message: string) {
call(warning, valid, message);
}

/** @see Same as {@link warning}, but only warn once for the same message */
export function noteOnce(valid: boolean, message: string) {
call(note, valid, message);
}
Expand All @@ -80,4 +92,3 @@ warningOnce.resetWarned = resetWarned;
warningOnce.noteOnce = noteOnce;

export default warningOnce;
/* eslint-enable */
8 changes: 8 additions & 0 deletions tests/raf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ describe('raf', () => {
it('cancel', done => {
let bamboo = false;

// Call some native raf
for (let i = 0; i < 10; i += 1) {
const nativeId = requestAnimationFrame(() => {});
cancelAnimationFrame(nativeId);
}

const id = raf(() => {
bamboo = true;
}, 2);
expect(raf.ids().has(id)).toBeTruthy();

raf.cancel(id);
expect(raf.ids().has(id)).toBeFalsy();

requestAnimationFrame(() => {
requestAnimationFrame(() => {
Expand Down

0 comments on commit 21bd73a

Please sign in to comment.