Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation for context without a contextwatchdog #461

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ckeditorcontext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export default class CKEditorContext<TContext extends Context = Context> extends
}

private async _initializeContextWatchdog( config?: ContextConfig ): Promise<void> {
if ( this.props.disableWatchdog ) {
return;
}
this.contextWatchdog = new ContextWatchdog( this.props.context!, this.props.watchdogConfig );

this.contextWatchdog.on( 'error', ( _, errorEvent ) => {
Expand Down Expand Up @@ -107,6 +110,7 @@ export default class CKEditorContext<TContext extends Context = Context> extends
id: PropTypes.string,
isLayoutReady: PropTypes.bool,
context: PropTypes.func as unknown as Validator<{ create( ...args: any ): Promise<any> } | undefined>,
disableWatchdog: PropTypes.bool,
watchdogConfig: PropTypes.object,
config: PropTypes.object,
onReady: PropTypes.func,
Expand All @@ -116,6 +120,7 @@ export default class CKEditorContext<TContext extends Context = Context> extends

interface Props<TContext extends Context> extends InferProps<typeof CKEditorContext.propTypes> {
context?: { create( ...args: any ): Promise<TContext> };
disableWatchdog?: boolean;
watchdogConfig?: WatchdogConfig;
config?: ContextConfig;
onReady?: ( context: Context ) => void; // TODO this should accept TContext (after ContextWatchdog release).
Expand Down
10 changes: 10 additions & 0 deletions tests/ckeditorcontext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ describe( '<CKEditorContext> Component', () => {
expect( component.contextWatchdog._crashNumberLimit ).to.equal( 678 );
} );

it( 'should not create a context watchdog if disableWatchdog flag is passed to config', async () => {
await new Promise( res => {
wrapper = mount( <CKEditorContext context={ ContextMock } onReady={ res } disableWatchdog={true}/> );
} );

const component = wrapper.instance();

expect( component.contextWatchdog ).to.be.null;
} );

it( 'should not create anything if the layout is not ready', async () => {
wrapper = mount( <CKEditorContext context={ ContextMock } isLayoutReady={ false }/> );

Expand Down