From b1eabfca2445f8603a2357b03c11aab9f3b48da9 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Fri, 6 Oct 2017 23:49:01 +0200 Subject: [PATCH] add toJSON method --- src/y-map.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/y-map.js b/src/y-map.js index 268be2e..966e6e6 100644 --- a/src/y-map.js +++ b/src/y-map.js @@ -94,6 +94,21 @@ export default function extendYMap (Y) { this.os = null this.map = null } + toJSON () { + var obj = {} + for (let key in this.contents) { + obj[key] = this.contents[key] + } + for (let key in this.opContents) { + let type = this.os.getType(this.opContents[key]) + if (type.toJSON != null) { + obj[key] = type.toJSON() + } else if (type.toString != null) { + obj[key] = type.toString() + } + } + return obj + } get (key) { // return property. // if property does not exist, return null