You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
816 B
31 lines
816 B
2 years ago
|
const wrapData = (data, relatedPathValues, basePath) => {
|
||
|
if (typeof data !== 'object' || data === null) return data
|
||
|
const propDef = {}
|
||
|
Object.keys(data).forEach((key) => {
|
||
|
let keyWrapper = null
|
||
|
propDef[key] = {
|
||
|
get() {
|
||
|
if (!keyWrapper) {
|
||
|
const keyPath = basePath.concat(key)
|
||
|
relatedPathValues.push({
|
||
|
path: keyPath,
|
||
|
value: data[key]
|
||
|
})
|
||
|
keyWrapper = wrapData(data[key], relatedPathValues, keyPath)
|
||
|
}
|
||
|
return keyWrapper
|
||
|
},
|
||
|
set() {
|
||
|
throw new Error('Setting data is not allowed')
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
return Object.create(Object.prototype, propDef)
|
||
|
}
|
||
|
|
||
|
const create = (data, relatedPathValues) => wrapData(data, relatedPathValues, [])
|
||
|
|
||
|
export default {
|
||
|
create
|
||
|
}
|