I'm builiding a local storage for my data for a Vue + Laravel SPA app.
The storage looks as such:
const Storage =
{
handler:
{
get: function(o, prop)
{
return localStorage.getItem('storage.data.' + prop)
},
set: function(o, prop, value)
{
localStorage.setItem('storage.data.' + prop, value)
}
}
}
Vue.prototype.$storage = new Proxy(Storage, Storage.handler)
Fairly simple, I would say.
The issue I'm having is, I want the code below to create all neccessary objects as it goes through:
this.$storage.auth.token.kohen = 'test'
To put more bluntly, I want objects auth
and token
to be created when I set kohen
, so I don't have to do:
this.$storage.auth = {}
this.$storage.auth.token = {}
The problem with that is, it runs get on auth
first - which also returns undefined
.