You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We may use no-setter computed() instead but intention is less obvious :
// ex. 2constx=ref(0)consto=reactive({x : computed(()=>x.value)// .. other mutable props .. })++o.x// warnings: Write operation failed: computed value is readonly
Feature request:
Vue should preserve immutable semantic when users assign a readonly() ref to a reactive property ( ex.1 ) ; and show warnings when immutable reactive properties are being mutated ( as if ex.2 ) .
End user experience:
When we receive a object wrapped in reactive() from "parent component" ( or "inject from provider" or "Pinia store instance" )
we're now confident to mutate any properties as data providers are now able-to and supposed-to handle access control for all data they provided in the single reactive/ref.
With Volar, we can even get early errors.
// ex. consume a Pinia store, mutate a readonly ref immutWalletimportuseMyStorefrom'./stores/myStore.js'conststore=useMyStore()//-> a reactiveconstonClick=()=>++store.immutWallet// Volar: Error: key 'immutWallet' is readonly.
Data providers setup access control for properties
constt=ref(0)// global time for ex.constel=ref()// in-tmpl ref for ex.onMounted(()=>provide('o',reactive({t: readonly(t),
el
})))setInterval(()=>++t.value,1000)
Data consumers try to access an immutable property
consto=inject('o')constonClick=()=>{o.el.dataset.triggerAt=o.t// get... oko.t=0// set... will warn in web console}
The text was updated successfully, but these errors were encountered:
What problem does this feature solve?
The Problem:
readonly()
immutable semantic silently lost on accessing :We may use no-setter
computed()
instead but intention is less obvious :Feature request:
Vue should preserve immutable semantic when users assign a
readonly()
ref to a reactive property ( ex.1 ) ; and show warnings when immutable reactive properties are being mutated ( as if ex.2 ) .End user experience:
When we receive a object wrapped in
reactive()
from "parent component" ( or "inject from provider" or "Pinia store instance" )we're now confident to mutate any properties as data providers are now able-to and supposed-to handle access control for all data they provided in the single reactive/ref.
With Volar, we can even get early errors.
This feature may immediately solve vuejs/pinia#872 (comment)
What does the proposed API look like?
Code sample
Data providers setup access control for properties
Data consumers try to access an immutable property
The text was updated successfully, but these errors were encountered: