@@ -3,7 +3,7 @@ import { Broadcast } from 'react-broadcast';
33import { Manager , generatePackageJSON } from 'smooshpack' ;
44import { listen } from 'codesandbox-api' ;
55
6- import { IFile , IFiles , IManagerState } from '../../types' ;
6+ import { IFile , IFiles , IManagerState , ISandpackContext } from '../../types' ;
77
88export interface State {
99 files : IFiles ;
@@ -34,7 +34,7 @@ export interface Props {
3434 | 'angular-cli'
3535 | 'preact-cli' ;
3636
37- onFileChange ?: ( files : IFiles ) => void ;
37+ onFileChange ?: ( files : IFiles , sandpack : ISandpackContext ) => void ;
3838}
3939
4040export default class SandpackProvider extends React . PureComponent <
@@ -138,7 +138,7 @@ export default class SandpackProvider extends React.PureComponent<
138138 this . setState ( { files } ) ;
139139
140140 if ( this . props . onFileChange ) {
141- this . props . onFileChange ( files ) ;
141+ this . props . onFileChange ( files , this . _getSandpackState ( ) ) ;
142142 }
143143 if ( this . manager ) {
144144 this . manager . updatePreview ( { files, template : this . props . template } ) ;
@@ -170,23 +170,25 @@ export default class SandpackProvider extends React.PureComponent<
170170 this . setState ( { openedPath : path } ) ;
171171 } ;
172172
173+ _getSandpackState = ( ) : ISandpackContext => {
174+ const { iframe, files, browserPath, openedPath, managerState } = this . state ;
175+ return {
176+ files,
177+ openedPath,
178+ managerState,
179+ openFile : this . openFile ,
180+ browserFrame : iframe ,
181+ updateFiles : this . updateFiles ,
182+ bundlerURL : this . manager ? this . manager . bundlerURL : undefined ,
183+ } ;
184+ } ;
185+
173186 render ( ) {
174187 const { children, className, style } = this . props ;
175188 const { iframe, files, browserPath, openedPath, managerState } = this . state ;
176189
177190 return (
178- < Broadcast
179- channel = "sandpack"
180- value = { {
181- files,
182- openedPath,
183- managerState,
184- openFile : this . openFile ,
185- browserFrame : iframe ,
186- updateFiles : this . updateFiles ,
187- bundlerURL : this . manager ? this . manager . bundlerURL : undefined ,
188- } }
189- >
191+ < Broadcast channel = "sandpack" value = { this . _getSandpackState ( ) } >
190192 < div style = { style } className = { `${ className ? className : '' } sandpack` } >
191193 { /* We create a hidden iframe, the bundler will live in this.
192194 We expose this iframe to the Consumer, so other components can show the full
0 commit comments