-
-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow consumer to further alter the behavior of isDraftable #405
Comments
I think that might be fixed if you would also share immer between the windows? |
How do you propose doing this? I'm not seeing how that could work. The problem is on this line: https://github.com/immerjs/immer/blob/master/src/common.js#L31 Immer only checks for objects created with the object prototype in its current scope. Not objects created in other windows |
I think a solution could be to add the symbol to check for as argument to
the `Immer` constructor, which is consistent with other not-common
customizations of immer.
…On Sat, Sep 28, 2019 at 3:04 AM Daniel Worsnup ***@***.***> wrote:
How do you propose doing this? I'm not seeing how that could work. The
problem is on this line:
https://github.com/immerjs/immer/blob/master/src/common.js#L31 Immer only
checks for objects created with the object prototype in its current scope.
Not objects created in other windows
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#405?email_source=notifications&email_token=AAN4NBBMKSACLWPQG2VSZO3QL23SJA5CNFSM4ILDNOJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD72OJJI#issuecomment-536143013>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAN4NBCIJMH7QX6NSHHJM5TQL23SJANCNFSM4ILDNOJA>
.
|
For the object check: this check (from redux toolkit) might work cross frames?
|
Closing for inactivity |
@mweststrate I think the one from lodash is better. what do you think ? export function isPlainObject(value: any): boolean {
if (!value || typeof value !== "object") return false
const proto = Object.getPrototypeOf(value)
if (proto === null) {
return true
}
const Ctor =
Object.hasOwnProperty.call(proto, "constructor") && proto.constructor
return (
typeof Ctor == "function" &&
Function.toString.call(Ctor) === objectCtorString
)
} |
🚀 Feature Proposal
I'm not 100% sure what this API would look like, but I'd like to see the mechanism for altering the behavior of
isDraftable
to be more configurable by the consumer. The current mechanism (applying theimmerable
symbol to objects that would otherwise be undraftable) is limiting for my use case.Motivation
In my app there are two window contexts (the top window and an iframe window context) in which objects are created, and these objects frequently get passed between the two contexts. Immer's current
isDraftable
predicate only returnstrue
for objects that are created in the same window context as itself, which means it only returnstrue
for objects that were created in the top window. Theimmerable
symbol could be used to solve this problem, but we would need to apply it in many places, whereas it would be simpler to have a way to tell Immer to take into account objects from eitherwindow
context.Example
Again, I'm not sure what it should look like, but one idea would be to allow the consumer to specify it's own
isDraftable
predicate that either A) overrides the built-inisDraftable
, or B) is used as a "final" check when all of the existingisDraftable
checks fail.Let me know your thoughts!
The text was updated successfully, but these errors were encountered: