-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
feat: ref api #62
feat: ref api #62
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit fc5cd6a:
|
@drcmda Would you be able to try this build and see if it works as expected? |
@dai-shi works! :-D blocks inner mutation, but ref equality still holds. |
@drcmda |
Published: https://www.npmjs.com/package/valtio/v/0.6.0 |
This feature is very helpful. Without bypassing the import { proxy, ref } from 'valtio';
export const state = proxy({
isConnecting: false,
signals: ref(new EventEmitter()),
connection: null
}); The following code will results in:
import { proxy, ref } from 'valtio';
export const state = proxy({
isConnecting: false,
signals: new EventEmitter(),
connection: null
});
// anywhere
const { connection, signals } = useSnapshot(state);
useEffect(() => {
signals.on('Notification', fn);
return () => {
return signals.off('Notification', fn);
};
}, [signals) @dai-shi is it intentional or a bug? |
@StarpTech You might want to try using |
It doesn't work. I'm wondering why it happened at all. It feels like a bug. See GoogleChrome/proxy-polyfill#20 (comment) |
Removing |
close #61
Summary
ref
will mark an object so that it won't be wrapped by proxies when used as a (nested) property.Usage
Caveat 1
Thisref
is for tracking mutations only.For render optimization (=useProxy(state)
use case), objects could wrapped by proxies if they are plain objects, but that would only happen on demand, so it shouldn't be a problem. It doesn't influence the state object either.Fixed in #65
Caveat 2