object-view
v1.0.1
Published
Take another view at your objects
Downloads
4
Readme
Object View
Enables placing views/masks on top of an object.
The masked object can then be modified using the view's structure. The source object itself is modified beneath it.
e.g.
Our source object
const real = {
title: 'My Story',
properties: {
desc: 'A short description',
nest: {
ed: true
}
}
}
The view describing how we would like our object to appear
const view = {
'title': 'label',
'properties.some': 'description',
'properties.nest.ed': 'available'
}
Apply the view to our object
const obj = ov(view, real)
Then obj
now looks like:
{
"label":"My Story",
"description":"A short description",
"available":true
}
You can then assign new values to these properties, like so:
obj.label = 'Another story'
obj.description = 'A different description'
obj.available = false
Our initial source object will now look like
{
title: 'Another story',
properties: {
desc: 'A different description',
nest: {
ed: false
}
}
}
For objects with complex structures several different views can be created.