Skip to content

Commit d5925cd

Browse files
author
Ives van Hoorne
committed
Update dispatch methods
1 parent caf8685 commit d5925cd

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

packages/codesandbox-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codesandbox-api",
3-
"version": "0.0.14",
3+
"version": "0.0.17",
44
"description": "",
55
"keywords": [],
66
"main": "dist/codesandbox.umd.js",

packages/codesandbox-api/src/dispatcher/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ function notifyFrames(message: Object) {
6868
function eventListener(e: MessageEvent) {
6969
const { data } = e;
7070

71-
notifyListeners(data, e.source);
71+
if (data && data.codesandbox) {
72+
notifyListeners(data, e.source);
73+
}
7274
}
7375

7476
/**

packages/react-sandpack/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-smooshpack",
3-
"version": "0.0.16",
3+
"version": "0.0.17",
44
"description": "",
55
"keywords": [],
66
"license": "SEE LICENSE.MD IN ROOT",
@@ -73,11 +73,12 @@
7373
"dependencies": {
7474
"classnames": "^2.2.5",
7575
"codemirror": "^5.35.0",
76+
"codesandbox-api": "^0.0.17",
7677
"codesandbox-import-utils": "^1.2.3",
7778
"react-broadcast": "^0.6.2",
7879
"react-codemirror2": "^4.0.1",
7980
"rollup-plugin-scss": "^0.4.0",
80-
"smooshpack": "^0.0.15"
81+
"smooshpack": "^0.0.17"
8182
},
8283
"peerDependencies": {
8384
"react": "^16.0.0"

packages/react-sandpack/src/components/SandpackProvider/SandpackProvider.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { Broadcast } from 'react-broadcast';
33
import { Manager, generatePackageJSON } from 'smooshpack';
4-
import { listen, dispatch } from 'codesandbox-api';
4+
import { listen } from 'codesandbox-api';
55

66
import {
77
IFile,
@@ -204,7 +204,9 @@ export default class SandpackProvider extends React.PureComponent<
204204
}
205205
});
206206

207-
dispatch({ type: 'get-transpiler-context' });
207+
if (this.manager) {
208+
this.manager.dispatch({ type: 'get-transpiler-context' });
209+
}
208210
});
209211

210212
_getSandpackState = (): ISandpackContext => {

packages/react-sandpack/stories/InTheWild.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import JSXAddon from 'storybook-addon-jsx';
55
import { withKnobs } from '@storybook/addon-knobs/react';
66

77
import SandpackProvider from '../src/components/SandpackProvider/index.ts';
8+
import SandpackConsumer from '../src/components/SandpackConsumer/index.ts';
89
import FileExplorer from '../src/components/FileExplorer/index.ts';
910
import BrowserPreview from '../src/components/BrowserPreview/index.ts';
1011
import TranspiledCodeView from '../src/components/TranspiledCodeView/index.ts';
@@ -48,6 +49,10 @@ stories.addWithJSX('one file', () => (
4849
overflow: 'hidden',
4950
}}
5051
/>
52+
53+
<SandpackConsumer>
54+
{sandpack => console.log(sandpack) || <div />}
55+
</SandpackConsumer>
5156
</div>
5257
</SandpackProvider>
5358
));

packages/sandpack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "smooshpack",
3-
"version": "0.0.15",
3+
"version": "0.0.17",
44
"description": "",
55
"keywords": [],
66
"main": "dist/sandpack.umd.js",
@@ -74,7 +74,7 @@
7474
"mapCoverage": true
7575
},
7676
"dependencies": {
77-
"codesandbox-api": "^0.0.14",
77+
"codesandbox-api": "^0.0.17",
7878
"codesandbox-import-utils": "^1.2.3"
7979
},
8080
"devDependencies": {

packages/sandpack/src/manager/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ export default class PreviewManager {
169169
});
170170
}
171171

172+
public dispatch(message: Object) {
173+
dispatch(message);
174+
}
175+
172176
private getFiles() {
173177
const { sandboxInfo } = this;
174178

0 commit comments

Comments
 (0)