Opting out from proxying globally #13040
-
Is it possible to opt-out the specific types from making proxies automatically, without littering the Asked ChatGTP, it suggested using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If the types are using classes then you might be able to use class Example {}
markRaw(Example.prototype) That does seem to work in the Playground. I'm not aware of a hook or mechanism that you can use to tell Vue not to add proxies to specific types, other than The suggestion to use reactivity transforms seems unrelated to your question. Reactivity transforms were for allowing refs to be used without having to write |
Beta Was this translation helpful? Give feedback.
-
That's one of the reason why I thought AI went haywire there. Full suggested code looks like this: import { createApp, reactive, markRaw } from 'vue';
import * as ol from 'openlayers';
// Create a custom reactivity transform
function customReactivityTransform(value) {
// Check if the value is an instance of any openlayers class
if (value instanceof ol.Map || value instanceof ol.View || value instanceof ol.Layer) {
return markRaw(value);
}
return reactive(value);
}
const app = createApp({
data() {
return {
// Example usage
map: new ol.Map({
// map configuration here
}),
view: new ol.View({
// view configuration here
}),
layer: new ol.Layer({
// layer configuration here
})
};
}
});
// Use the custom reactivity transform globally
app.config.globalProperties.$reactiveTransform = customReactivityTransform;
app.mount('#app'); At first I was very surprised and excited when I got this piece since it seemed like it was supposed to do exactly what I wanted the way I wanted, but hopes die soon. Thanks for the prototype suggestion, will try that next week! |
Beta Was this translation helpful? Give feedback.
If the types are using classes then you might be able to use
markRaw
on the prototype:That does seem to work in the Playground.
I'm not aware of a hook or mechanism that you can use to tell Vue not to add proxies to specific types, other than
markRaw
.The suggestion to use reactivity transforms seems unrelated to your question. Reactivity transforms were for allowing refs to be used without having to write
.value
explicitly, they didn't remove proxies.