Skip to content
Snippets Groups Projects
Commit 4e371cbd authored by Philipp Sautner's avatar Philipp Sautner
Browse files

Merge branch '720-LocalStorage-Share-Sautner' into 'staging'

Adds strinigfy/parse to parse JSON but stringify data to work with

Closes #720

See merge request arsnova/frag.jetzt!726
parents b9599cae d2d5c097
No related merge requests found
...@@ -6,21 +6,21 @@ import { Injectable } from '@angular/core'; ...@@ -6,21 +6,21 @@ import { Injectable } from '@angular/core';
export class LocalStorageShareService { export class LocalStorageShareService {
constructor() { constructor() {
window.addEventListener('message', this.messageHandler, false); window.addEventListener('message', this.messageHandler.bind(this), false);
} }
messageHandler(event) { messageHandler(event) {
const { action, key, value} = event.data; const { action, key, value} = JSON.parse(event.data);
if (action === 'save') { if (action === 'save') {
window.localStorage.setItem(key, JSON.stringify(value)); window.localStorage.setItem(key, JSON.stringify(value));
} else if (action === 'get') { } else if (action === 'get') {
const obj = JSON.parse(window.localStorage.getItem(key)); const obj = JSON.parse(window.localStorage.getItem(key));
if(obj !== null) { if(obj !== null) {
event.source.postMessage({ event.source.postMessage(JSON.stringify({
action: 'returnData', action: 'returnData',
key, key,
obj obj
}, '*'); }), '*');
} }
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment