generate input/output bindings to the GridJS package #182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It all started when I saw this comment:
// TODO: auto generate Inputs/Output to easily sync with grid-js main package
I spent several hours trying to figure out how to accomplish this, and after looking at the implementation of https://github.com/microsoft/ts-gyb, I tried writing my own script for transforming the GridJS TypeScript interfaces into something we could use in this library for input/output bindings on the Angular component.
The script that does the heavy lifting is at
scripts/update-bindings.mjs
and is executed by callingnx update-bindings gridjs-angular
. The script uses the TypeScript package to get type information fromnode_modules/gridjs/dist/src/events.d.ts
(whereGridEvents
is defined) andnode_modules/gridjs/dist/src/config.d.ts
(whereConfig
is defined), collecting the data we need into an object. That object is then passed to MustacheJS which transforms the data into a TypeScript class. I specifically didn't want the main library component file to be auto-generated (as it's more painful to make changes to a template), so I tried to keep the generated code to bindings only, and members that require the names of all the properties from either Config or GridEvents. Thus the output file is an abstract class with all the@Input()
and@Output()
decorators (the boilerplate). Then the main export of the library,GridJsAngularComponent
, extends the base class and handles any other custom things needed for the Angular wrapper.I also made sure that the generated code uses Angular Signals, which should help with at least near-term future-proofing of the library.
Finally, I cleaned up some things that didn't need to be there (like the empty routes file and accompanying router-outlet) and spruced up the Readme. I also expanded the demo to use more of GridJS's features to make it a better sample of the library's usage.
I'm eager to do some unit testing, but this PR is already getting pretty large and disruptive so I'd prefer to add those in a separate PR.
I tried to maintain backwards compatibility by adding that alias for the
gridLoad
event (not sure if it works due to this GridJS issue, but at least therowClick
/cellClick
events work so I assume it should be OK).Please, provide as much feedback as necessary. Hoping this moves the library forward in a positive way!