File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
src/plugins/json-schema-validator Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -10,15 +10,24 @@ const swagger2Schema = YAML.load(swagger2SchemaYaml)
1010const oas3Schema = YAML . load ( oas3SchemaYaml )
1111
1212// Lazily created promise worker
13- let _promiseWorker
14- const promiseWorker = ( ) => {
15- if ( ! _promiseWorker )
13+ let _promiseWorker = null
14+
15+ const getWorker = ( ) => ( ) => {
16+ if ( _promiseWorker === null ) {
1617 _promiseWorker = new PromiseWorker ( new JsonSchemaWebWorker ( ) )
18+ }
1719 return _promiseWorker
1820}
1921
20- export const addSchema = ( schema , schemaPath = [ ] ) => ( ) => {
21- promiseWorker ( ) . postMessage ( {
22+ const terminateWorker = ( ) => ( ) => {
23+ if ( _promiseWorker ) {
24+ _promiseWorker . _worker . terminate ( )
25+ _promiseWorker = null
26+ }
27+ }
28+
29+ export const addSchema = ( schema , schemaPath = [ ] ) => ( { jsonSchemaValidatorActions } ) => {
30+ jsonSchemaValidatorActions . getWorker ( ) . postMessage ( {
2231 type : "add-schema" ,
2332 payload : {
2433 schemaPath,
@@ -95,7 +104,8 @@ export const validateImmediate = ({ spec, path = [] }) => system => {
95104export const validateWithBaseSchema = ( { spec, path = [ ] } ) => system => {
96105 const errSource = system . jsonSchemaValidatorSelectors . errSource ( )
97106
98- return promiseWorker ( )
107+
108+ return system . jsonSchemaValidatorActions . getWorker ( )
99109 . postMessage ( {
100110 type : "validate" ,
101111 payload : {
@@ -146,6 +156,8 @@ export default function() {
146156 statePlugins : {
147157 jsonSchemaValidator : {
148158 actions : {
159+ getWorker,
160+ terminateWorker,
149161 addSchema,
150162 validate,
151163 handleResults,
You can’t perform that action at this time.
0 commit comments