I defined a mobx map as below:
@observable editors = observable.map();
then I added object on the editors
as below:
editors.set(key, {
alias: 'alias-1',
message: 'hello',
})
when I get the object from editor
as below:
let myEditor = editors.get(key)
the returned object myEditor
has some builtin functions such as:
$mobx:ObservableObjectAdministration
get alias:function ()
set alias:function ()
get message:function ()
set message:function ()
I wander how I can get a plain javascript object from editor
?
observable defines a trackable field that stores the state. action marks a method as action that will modify the state. computed marks a getter that will derive new facts from the state and cache its output.
Usage: toJS(value) Recursively converts an observable object to a JavaScript object. Supports observable arrays, objects, Maps and primitives.
observable. ref will only track reference changes to the object, which means that you will need to change the whole object in order to trigger the reaction. So if you, for example, have an observable array that is tracked by reference, the contents of the array will not be tracked.
You can use toJS.
Example
class MyStore {
@observable editors = observable.map({});
}
const myStore = new MyStore();
myStore.editors.set('example', {
alias: 'alias-1',
message: 'hello'
});
console.log(toJS(myStore.editors));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With