-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent accidental accessing of
ref
- Loading branch information
Showing
8 changed files
with
61 additions
and
27 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,3 @@ | ||
export const PixiReactIgnoredProps = Object.freeze([ | ||
'draw', | ||
]); |
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 @@ | ||
export const ReactIgnoredProps = Object.freeze([ | ||
'children', | ||
'key', | ||
'ref', | ||
]); |
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,22 @@ | ||
/** | ||
* Clones an object without any of the ignored keys. | ||
* | ||
* @param {Record<string, any>} object The object to clone. | ||
* @param {string[]} [ignoredKeys] An array of keys to ignore when cloning the object. | ||
* @returns {Record<string, any>} The cloned object. | ||
*/ | ||
export function gentleClone(object, ignoredKeys = []) | ||
{ | ||
/** @type {Record<string, any>} */ | ||
const cloneBase = {}; | ||
|
||
return Object.entries(object).reduce((accumulator, [key, value]) => | ||
{ | ||
if (!ignoredKeys.includes(key)) | ||
{ | ||
accumulator[key] = value; | ||
} | ||
|
||
return accumulator; | ||
}, cloneBase); | ||
} |
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,16 @@ | ||
import { PixiReactIgnoredProps } from '../constants/PixiReactIgnoredProps.js'; | ||
import { ReactIgnoredProps } from '../constants/ReactIgnoredProps.js'; | ||
import { gentleClone } from './gentleClone.js'; | ||
|
||
const IGNORED_PROPS = ReactIgnoredProps.concat(PixiReactIgnoredProps); | ||
|
||
/** | ||
* Clones a props object, excluding keys that are special to React and Pixi React. | ||
* | ||
* @param {Record<string, any>} props The props object to clone. | ||
* @returns {Record<string, any>} The cloned props. | ||
*/ | ||
export function gentleCloneProps(props) | ||
{ | ||
return gentleClone(props, IGNORED_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