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

Typings for Form#on and FormEditor#on are incorrect #159

Closed
nikku opened this issue Aug 30, 2021 · 4 comments · Fixed by #232
Closed

Typings for Form#on and FormEditor#on are incorrect #159

nikku opened this issue Aug 30, 2021 · 4 comments · Fixed by #232
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation editor ux viewer
Milestone

Comments

@nikku
Copy link
Member

nikku commented Aug 30, 2021

Describe the Bug

We current expose type definitions for Form#on and FormEditor#on that require users to use a third priority=number argument. We should fix our type definitions to allow both forms, two arg and three argument invocations to the list:

form.on('change', function(event) { });
form.on('change', 500, function(event) { });

Expected Behavior

As a user I'd like to use the simple form of registering for events. That form is referenced and documented, too.

Environment

  • Host (Browser/Node version), if applicable: any
  • OS: Windows
  • Library version: v0.4.1

Reported via Camunda Cloud Devs.

@nikku nikku added bug Something isn't working documentation Improvements or additions to documentation editor viewer ux labels Aug 30, 2021
@nikku nikku added this to the F4 milestone Aug 30, 2021
@barmac
Copy link
Member

barmac commented Sep 1, 2021

Related to microsoft/TypeScript#25590

@nikku nikku added the backlog Queued in backlog label Sep 3, 2021 — with bpmn-io-tasks
@dfulgham
Copy link
Contributor

dfulgham commented Mar 9, 2022

Sorry if this is not a good way of handling this, but would something like this take care of this issue?

Add the following typedef's

/**
 * @typedef { (type:FormEvent,priorityOrHandler:number,handler:Function) => void } OnEventWithPriority;
 * @typedef { (type:FormEvent,priorityOrHandler:Function) => void } OnEventWithOutPriority;
 * @typedef { OnEventWithPriority & OnEventWithOutPriority} OnEventType
 * /

then create a private definition (#onEvent) for the on method and assign (this.on = #onEvent) in the constructor. This will result in the overload being typed correctly in Typescript and in the IDE

...

/**
   *  private OnEvent function definition
   * 
   */
  #onEvent = (type,priorityOrHandler,handler) => {
    if (typeof priorityOrHandler !== 'number' && typeof handler === 'undefined') {
      handler = priorityOrHandler;
      priorityOrHandler = 0;
    }
    this.get('eventBus').on(type, priorityOrHandler, handler);
  }

  /**
   * @constructor
   * @param {FormOptions} options
   */
  constructor(options = {}) {

    /**
     * @type {OnEventType}
    */
    this.on = this.#onEvent;

...
}

@bpmn-io-tasks bpmn-io-tasks bot removed the backlog Queued in backlog label Mar 9, 2022
@MaxTru MaxTru added the ready Ready to be worked on label Mar 10, 2022 — with bpmn-io-tasks
@MaxTru MaxTru self-assigned this Mar 11, 2022
@dfulgham
Copy link
Contributor

in my PR its not accepting the #onEvent private class method, I could just change it to _onEvent ? I have the same version of all libraries and it compiles and tests fine on my local machine, but the testing environment on CI is failing on the # character.

@nikku
Copy link
Member Author

nikku commented Mar 13, 2022

This would fix it, indeed.

Please change # to _. We try to avoid using the latest of JS but stick to certain evergreen patterns (_ for private) instead.

@bpmn-io-tasks bpmn-io-tasks bot removed the ready Ready to be worked on label Mar 14, 2022
@MaxTru MaxTru added the in progress Currently worked on label Mar 14, 2022 — with bpmn-io-tasks
dfulgham added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
MaxTru added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
MaxTru added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
MaxTru added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
MaxTru added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
MaxTru added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
MaxTru added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
MaxTru added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
MaxTru added a commit to dfulgham/form-js that referenced this issue Mar 15, 2022
@fake-join fake-join bot closed this as completed in #232 Mar 15, 2022
@bpmn-io-tasks bpmn-io-tasks bot removed the in progress Currently worked on label Mar 15, 2022
fake-join bot pushed a commit that referenced this issue Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation editor ux viewer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants