Skip to content

feat: introduce AbstractEvent and upgrade to node 20.x #2

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

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

CMCDragonkai
Copy link
Member

@CMCDragonkai CMCDragonkai commented Aug 30, 2023

Description

This introduces the AbstractEvent in a similar vein to AbstractError in js-errors. It is supposed to be used as the root event class for all event related operations to help govern push-flows.

Because AbstractEvent uses CustomEvent this bumps up our nodejs to 20.x which is the next LTS, and has CustomEvent available as a global.

Notice updates to:

  • .eslintrc
  • pkgs.nix
  • shell.nix

Any downstream packages using this will need to upgrade correspondingly.

// These all work now
new AbstractEvent();
new AbstractEvent(undefined);
new AbstractEvent(undefined, undefined);
new AbstractEvent(undefined, { detail: null });

class Event1 extends AbstractEvent<string> {}

const e1 = new Event1({ detail: 'test' });
console.log(e1.type);
console.log(e1.detail);
console.log(e1.clone());

class Event2 extends AbstractEvent<string> {
  constructor(options?: CustomEventInit<string>) {
    super(Event2.name, options, arguments);
  }
}

const e2 = new Event2({ detail: 'test' });
console.log(e2.clone());

Further instructions on utilisation will be in the README.md.

Issues Fixed

Tasks

  • 1. Added AbstractEvent
  • 2. Integrate it to EventAny
  • 3. Test AbstractEvent uses
  • 4. Update README.md with proper utilisation

Final checklist

  • Domain specific tests
  • Full tests
  • Updated inline-comment documentation
  • Lint fixed
  • Squash and rebased
  • Sanity check the final build

@CMCDragonkai CMCDragonkai self-assigned this Aug 30, 2023
@ghost
Copy link

ghost commented Aug 30, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@CMCDragonkai
Copy link
Member Author

It is important to realise that .clone is a shallow copy of the constructor parameters. So if you pass an object as the detail initially and clone it, the detail of the new event will still point to the old object.

@CMCDragonkai CMCDragonkai force-pushed the feature-abstract-event branch from 59720ec to 322eb3d Compare August 30, 2023 05:50
@CMCDragonkai
Copy link
Member Author

Weird, the node 20 upgrade may have introduced the instanceof TypeError problem. Let me check.

Otherwise tests are done.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Aug 30, 2023

So this produces false in jest:

try { new CustomEvent('abc', 'abc') } catch (e) { console.log(e instanceof TypeError); }

But it works on NodeJS. I think this is a jest error.

@CMCDragonkai
Copy link
Member Author

swc-project/jest#160

@CMCDragonkai
Copy link
Member Author

In the mean time we will just check the exception name which should work portably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant