From 84e33606dec8021dec81c9d21e7e57b1d25a6ef6 Mon Sep 17 00:00:00 2001 From: dfulgham Date: Mon, 14 Mar 2022 19:43:33 -0700 Subject: [PATCH] fix: adding jsdoc type defs to Form#on and FormEditor#on methods refs #159 --- packages/form-js-editor/src/FormEditor.js | 45 ++++++++++++---------- packages/form-js-viewer/src/Form.js | 47 ++++++++++++----------- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/packages/form-js-editor/src/FormEditor.js b/packages/form-js-editor/src/FormEditor.js index 43d50e563..db86fec6f 100644 --- a/packages/form-js-editor/src/FormEditor.js +++ b/packages/form-js-editor/src/FormEditor.js @@ -1,19 +1,8 @@ +import { clone, createFormContainer, createInjector, schemaVersion } from '@bpmn-io/form-js-viewer'; import Ids from 'ids'; - -import { - isString, - set -} from 'min-dash'; - -import { - createInjector, - clone, - createFormContainer, - schemaVersion -} from '@bpmn-io/form-js-viewer'; +import { isString, set } from 'min-dash'; import core from './core'; - import EditorActionsModule from './features/editor-actions'; import KeyboardModule from './features/keyboard'; import ModelingModule from './features/modeling'; @@ -33,6 +22,10 @@ const ids = new Ids([ 32, 36, 1 ]); * properties: FormEditorProperties, * schema: Schema * } } State + * + * @typedef { (type:string,priority:number,handler:Function) => void } OnEventWithPriority; + * @typedef { (type:string,handler:Function) => void } OnEventWithOutPriority; + * @typedef { OnEventWithPriority & OnEventWithOutPriority} OnEventType */ /** @@ -40,12 +33,30 @@ const ids = new Ids([ 32, 36, 1 ]); */ export default class FormEditor { + + /** + * private OnEvent function definition + * + */ + _onEvent = (type,priority,handler) => { + if (typeof priority === 'function' && typeof handler === 'undefined') { + handler = priority; + priority = 0; + } + this.get('eventBus').on(type, priority, handler); + } + /** * @constructor * @param {FormEditorOptions} options */ constructor(options = {}) { + /** + * @type {OnEventType} + */ + this.on = this._onEvent; + /** * @public * @type {String} @@ -221,14 +232,6 @@ export default class FormEditor { this._setState({ properties }); } - /** - * @param {string} type - * @param {number} priority - * @param {Function} handler - */ - on(type, priority, handler) { - this.get('eventBus').on(type, priority, handler); - } /** * @param {string} type diff --git a/packages/form-js-viewer/src/Form.js b/packages/form-js-viewer/src/Form.js index d63f72a91..c48033d89 100644 --- a/packages/form-js-viewer/src/Form.js +++ b/packages/form-js-viewer/src/Form.js @@ -1,19 +1,8 @@ import Ids from 'ids'; - -import { - get, - isString, - set -} from 'min-dash'; - -import { - clone, - createInjector, - createFormContainer, - pathStringify -} from './util'; +import { get, isString, set } from 'min-dash'; import core from './core'; +import { clone, createFormContainer, createInjector, pathStringify } from './util'; /** * @typedef { import('./types').Injector } Injector @@ -32,8 +21,14 @@ import core from './core'; * properties: FormProperties, * schema: Schema * } } State + * + * @typedef { (type:FormEvent,priority:number,handler:Function) => void } OnEventWithPriority; + * @typedef { (type:FormEvent,handler:Function) => void } OnEventWithOutPriority; + * @typedef { OnEventWithPriority & OnEventWithOutPriority} OnEventType */ + + const ids = new Ids([ 32, 36, 1 ]); /** @@ -41,12 +36,29 @@ const ids = new Ids([ 32, 36, 1 ]); */ export default class Form { + /** + * private OnEvent function definition + * + */ + _onEvent = (type,priority,handler) => { + if (typeof priority === 'function' && typeof handler === 'undefined') { + handler = priority; + priority = 0; + } + this.get('eventBus').on(type, priority, handler); + } + /** * @constructor * @param {FormOptions} options */ constructor(options = {}) { + /** + * @type {OnEventType} + */ + this.on = this._onEvent; + /** * @public * @type {String} @@ -296,15 +308,6 @@ export default class Form { this._setState({ properties }); } - /** - * @param {FormEvent} type - * @param {number} priority - * @param {Function} handler - */ - on(type, priority, handler) { - this.get('eventBus').on(type, priority, handler); - } - /** * @param {FormEvent} type * @param {Function} handler