liriliri / luna

UI library
https://luna.liriliri.io
MIT License
250 stars 22 forks source link

[Luna Object Viewer] serializable #2

Closed futurist closed 3 years ago

futurist commented 3 years ago

Are there any possible to serialize the objects in Object Viewer, since sometimes there's a need to transport the output of Object Viewer eg. via postMessage as below:

parent.postMessage(ObjectViewer.set({x:1}), '*')

since some objects cannot be cloned via postMessage, but JSON.stringify will destroy the structure(eg. no getter/setter/prototype...), and ObjectViewer cannot serialize to HTML String now.

Possible solution like serialize to v-dom objects that can safely transport via postMessage, then render the parent window to DOM.

Any idea this this?

surunzi commented 3 years ago

It's not documented but you can use licia/stringifyAll and LunaObjectViewer.Static to achieve your goal.

const stringifyAll = require('licia/stringifyAll')
const objectViewer = new LunaObjectViewer.Static(document.getElementById('container'))
const locationData = stringifyAll(location, {
  unenumerable: true,
  accessGetter: true,
  timeout: 500
})
objectViewer.set(locationData)