Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix: keep dev pane backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Sep 10, 2018
1 parent e395d33 commit cd0dd79
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/container/app-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface AppPaneProps {
pane: Types.AppPane;
force?: boolean;
children: React.ReactNode;
size?: { width: number | string; height: number | string };
defaultSize?: { width: number | string; height: number | string };
enable?: { top?: boolean; right?: boolean; bottom?: boolean; left?: boolean };
minWidth?: number;
Expand All @@ -26,7 +27,7 @@ export class AppPane extends React.Component<AppPaneProps> {
return null;
}

const paneSize = props.pane ? app.getPaneSize(props.pane) : undefined;
const paneSize = props.size || props.pane ? app.getPaneSize(props.pane) : undefined;

const defaultSize = paneSize
? { width: paneSize.width, height: paneSize.height }
Expand Down
10 changes: 10 additions & 0 deletions src/container/pane-development-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ export class PaneDevelopmentEditor extends React.Component {
scheduler: fn => setTimeout(fn, 1000)
}
);

Mobx.autorun(() => {
const value = storeEnhancer.getTypeScript();

if (value === this.editor.getValue() && storeEnhancer.getJavaScript() !== 'undefined') {
return;
}

this.editor.setValue(value);
});
}

public componentWillUnmount(): void {
Expand Down
18 changes: 18 additions & 0 deletions src/container/view-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export class ViewDetails extends React.Component {
public render(): JSX.Element {
const props = this.props as { store: ViewStore };

/**
* TODO: Remove before releasing BETA
* Hack for backwards compat with versions that computed js output instead of saving -
* for those we have to transpile the ts payload once, thus create an editor
*/
const forceEditor =
!props.store.getApp().isVisible(Types.AppPane.DevelopmentPane) &&
typeof props.store
.getProject()
.getUserStore()
.getEnhancer()
.getJavaScript() === 'undefined';

return (
<React.Fragment>
<AppPane
Expand Down Expand Up @@ -80,6 +93,11 @@ export class ViewDetails extends React.Component {
>
<PaneDevelopmentEditor />
</AppPane>
{forceEditor && (
<div style={{ position: 'fixed', top: '100vh' }}>
<PaneDevelopmentEditor />
</div>
)}
</div>
<AppPane
pane={Types.AppPane.PropertiesPane}
Expand Down
14 changes: 9 additions & 5 deletions src/model/user-store-enhancer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// import * as Fs from 'fs';
import * as Mobx from 'mobx';
import * as Types from '../types';
// import * as TypeScript from 'typescript';
import { UserStore } from './user-store';
import { DesignTimeUserStore } from './design-time-user-store';
import * as uuid from 'uuid';
import * as VM from 'vm';

// const MemoryFilesystem = require('memory-fs');

export interface UserStoreEnhancerModule {
onStoreCreate(store: DesignTimeUserStore): DesignTimeUserStore;
}
Expand Down Expand Up @@ -115,7 +111,11 @@ export class UserStoreEnhancer {
}

public static from(serialized: Types.SerializedUserStoreEnhancer): UserStoreEnhancer {
return new UserStoreEnhancer(serialized || {});
return new UserStoreEnhancer({
id: serialized.id,
typeScript: serialized.typeScript || serialized.code || '',
javaScript: serialized.javaScript
});
}

public getApi(): string {
Expand All @@ -126,6 +126,10 @@ export class UserStoreEnhancer {
return this.id;
}

public getJavaScript(): string {
return this.javaScript;
}

public getTypeScript(): string {
return this.typeScript;
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/user-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export interface SerializedUserStoreReference {
}

export interface SerializedUserStoreEnhancer {
/** @deprecated */
code?: string;
model: ModelName.UserStoreEnhancer;
id: string;
typeScript: string;
Expand Down

0 comments on commit cd0dd79

Please sign in to comment.