Skip to content

Commit

Permalink
AppComponent: Backwards compatible state initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
crnkjck committed Mar 12, 2023
1 parent c442a87 commit dd85409
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/AppComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import React, { useEffect, useRef } from 'react';
import React from 'react';
import ElmComponent from 'react-elm-components'
import './static/css/main.iso.css';
import './static/css/all.iso.css';
const Elm = require('./elm-editor.js').Elm;

function prepare(initialState) {
if (typeof(initialState) == "string") {
// Backwards compatibility
// State is now a JSON value, but was stringified JSON before
try {
initialState = JSON.parse(initialState);
} catch (_) {
initialState = null;
}
}
const instance = {
initialState,
state: null,
state: initialState,
triggerStateUpdate: null
};
const getState = (instance) => {
if (instance.triggerStateUpdate) {
console.log("State before triggering update", instance.state);
// console.log("Triggering tableau editor state update");
instance.triggerStateUpdate();
console.log("State after triggering update", instance.state);
// console.log("Triggered tableau editor state update");
}
return instance.state;
}
Expand All @@ -28,9 +37,11 @@ function AppComponent(props) {
const instance = props.instance;
const setupPorts = (ports) => {
ports.onChange.subscribe( () => {
// console.log("Tableau editor has changed");
props.onStateChange();
});
ports.onStore.subscribe( (state) => {
// console.log("Tableau editor sent state to store");
instance.state = state;
})
instance.triggerStateUpdate = () =>
Expand Down

0 comments on commit dd85409

Please sign in to comment.