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

feat!: upgrade to Aurelia 2, closes #709 #1038

Merged
merged 18 commits into from
Sep 27, 2023

Conversation

MaximBalaganskiy
Copy link
Collaborator

@MaximBalaganskiy MaximBalaganskiy commented Aug 8, 2023

As discussed, copied the upgraded files keeping the original location.
I was a bit confused by the demo app structure, so I've modified it just enough that it compiles.
Non-converted TS files got "ts_old" extension so that compiler does not pick them.

One thing that got me during conversion is that in many examples the mock data method mutates the array AFTER it's already bound to an element. This results in weird grid issues. So the way to do it was to build an array first and then assign to the field.

package.json Outdated Show resolved Hide resolved
src/aurelia-slickgrid/custom-elements/aurelia-slickgrid.ts Outdated Show resolved Hide resolved
src/aurelia-slickgrid/extensions/slickRowDetailView.ts Outdated Show resolved Hide resolved
src/aurelia-slickgrid/services/aureliaUtil.service.ts Outdated Show resolved Hide resolved
src/examples/slickgrid/example19.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
@ghiscoding
Copy link
Owner

ghiscoding commented Aug 9, 2023

@MaximBalaganskiy great thanks a lot for this PR, I've done a quick review without running the code yet. You could also give me access to write on your branch so that I could maybe fix some stuff myself within the same PR if possible (or I could merge and fix them later since it's on the next branch anyway).

Side note, we're working (mainly myself) on the next SlickGrid (core lib) as well and there's still more work to do on that project, I've converted that old JS code project to TypeScript and ES6/ESM (see our SlickGrid v5 Roadmap and I'll probably want to align the releases at the same time as the Au2 support since there are some breaking changes in the core lib as well (we'll no longer have the SlickGrid (core) on the Slick window object, we'll be using regular imports instead and users will have to change code a bit in some of the demos, i.e. the Example 3 uses Slick.GlobalEditor that will have to be replaced by import { SlickGlobalEditor } from 'slickgrid' (or from 'aurelia-slickgrid' if I re-export it, I'm not sure yet)....

anyway long story short, I assume there's still work until around Sept. (back to school lol) on that side of it as well.

if (command && Slick.GlobalEditorLock.cancelCurrentEdit()) {
command.undo();
this.aureliaGrid.slickGrid.gotoCell(command.row, command.cell, false);
}

@MaximBalaganskiy
Copy link
Collaborator Author

The access should be there. As for the timeframe, I'm personally not in a rush, I've got an Aurelia1 project which is not in production (might not even be released in the end) and upgrading it is not on my list atm.

@ghiscoding ghiscoding changed the title Upgrade to AU2 feat!: upgrade to Aurelia 2, closes #709 Aug 10, 2023
@@ -108,13 +99,26 @@ export class AureliaSlickgridCustomElement {
private _isLocalGrid = true;
private _paginationOptions: Pagination | undefined;
private _registeredResources: ExternalResource[] = [];
private _columnDefinitionObserver: ICollectionObserver<CollectionKind.array>;
private _columnDefinitionsSubscriber: ICollectionSubscriber = {
handleCollectionChange: () => {
Copy link
Owner

@ghiscoding ghiscoding Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaximBalaganskiy
I'm back to working on this migration and found that this _columnDefinitionObserver only works once and not after, would you have any clue why that is?

to replicate the issue, you can get latest code and go to Example 3 then click on the "Dynamically Duplicate Title Column" button multiple times, it only add an extra column on the first time but not after and after debugging and adding a console log in here, I see that the subscriber only worked once

I should have wrote my comment on the subscribed line, it's basically the following lines of code (at line 597)

this._columnDefinitionObserver = this.observerLocator.getArrayObserver(this.columnDefinitions);
this._columnDefinitionObserver.subscribe(this._columnDefinitionsSubscriber);

@MaximBalaganskiy
Copy link
Collaborator Author

MaximBalaganskiy commented Sep 15, 2023 via email

@ghiscoding
Copy link
Owner

ghiscoding commented Sep 15, 2023

I think replacing the array makes the subscription inactive. The first time it works because you push first. Either do not replace the array or resubscribe when it changes.

On Fri, 15 Sep 2023 at 1:46 pm, Ghislain B. @.> wrote: @.* commented on this pull request. --------------------

I digged into Aurelia 2 docs and found that the xChagned is still supported (as per docs) and if I add back simple code like this

columnDefinitionsChanged(newCols, oldCols) {
    console.log('columns changed', newCols, oldCols);
}

then the console log does get increase by another column every time I click the button. The only thing that I see from Au2 docs is that compare to Au1 it doesn't call the initial Changed event but we can call it ourselves from the bound() method... so was there any reason you decided to go with the approach you had? Was it to make the code a bit cleaner or...? Should I put back previous implementation with columnDefinitionsChanged?

Either do not replace the array or resubscribe when it changes.

Well that goes against what the user were able to do in Au1 and I still want to support this use case anyway, users can and should still be able to change the column definitions at any point in time

@MaximBalaganskiy
Copy link
Collaborator Author

MaximBalaganskiy commented Sep 15, 2023 via email

@ghiscoding
Copy link
Owner

ok no problem, I'll add it back since it worked better, I just might need to run it once for the initial load to make it the same as Au1 but at least it should make it work again :)

Thanks for the info... and time to go to bed, it's passed midnight here :O

@ghiscoding
Copy link
Owner

ghiscoding commented Sep 16, 2023

@MaximBalaganskiy
Looking back at the code, it looks like I need both because just one doesn't fulfill all use cases

  1. columnDefinitionsChanged for assignment like this.columns = newColumns[...]; or .slice()
  2. getArrayObserver, which used to be bindingEngine.collectionObserver, for bindings and array methods like .push, .pop and others...

I see that you migrate step 2 because of this Au2 migration BindingEngine has been removed in v2 comment but with the current bindingEngine.collectionObserver with Au1, it was working fine and I only needed to create and subscribed to the observer just once in the bind lifecycle and I was done, but it looks like with Au2 the getArrayObserver really does need to be re-subscribed like you mentioned earlier since it seems to lose its subscription somehow. Do you know why that is? Do you know if there's something else that I can use which can combine both assignment and array methods observing?

I currently got it working by using both and re-subscribing the observer whenever columnDefinitionsChanged gets called when reassigning but I wonder if that is the best way to go in Au2?

// subscribe to column definitions assignment changes with BindingEngine
// assignment changes are not triggering a "changed" event https://stackoverflow.com/a/30286225/1212166
// also binding docs https://github.com/aurelia/binding/blob/master/doc/article/en-US/binding-observables.md#observing-collections
this.subscriptions.push(
this.bindingEngine.collectionObserver(this.columnDefinitions)
.subscribe(this.columnDefinitionsChanged.bind(this))
);
}
columnDefinitionsChanged() {
this._columnDefinitions = this.columnDefinitions;
if (this._isGridInitialized) {
this.updateColumnDefinitionsList(this.columnDefinitions);
}
if (this._columnDefinitions.length > 0) {
this.copyColumnWidthsReference(this._columnDefinitions);
}
}

@MaximBalaganskiy
Copy link
Collaborator Author

MaximBalaganskiy commented Sep 16, 2023 via email

- `columnDefinitionsChanged` binding is only good for assignment but we also need to watch for changes via array methods like (push, pop, ...) so for that we also need an array observer
@codecov
Copy link

codecov bot commented Sep 16, 2023

Codecov Report

Merging #1038 (e8a625b) into next (caa54d9) will decrease coverage by 76.48%.
The diff coverage is 53.45%.

❗ Current head e8a625b differs from pull request most recent head beedbe1. Consider uploading reports for the commit beedbe1 to get more accurate results

@@             Coverage Diff             @@
##             next    #1038       +/-   ##
===========================================
- Coverage   99.29%   22.80%   -76.48%     
===========================================
  Files          15        8        -7     
  Lines         974      895       -79     
  Branches      331      310       -21     
===========================================
- Hits          967      204      -763     
- Misses          7      691      +684     
Files Coverage Δ
...aurelia-slickgrid/extensions/slickRowDetailView.ts 100.00% <100.00%> (ø)
.../aurelia-slickgrid/services/aureliaUtil.service.ts 100.00% <100.00%> (ø)
...rc/aurelia-slickgrid/services/container.service.ts 100.00% <100.00%> (ø)
...c/aurelia-slickgrid/services/translater.service.ts 100.00% <100.00%> (ø)
src/aurelia-slickgrid/services/utilities.ts 100.00% <100.00%> (ø)
...urelia-slickgrid/value-converters/asgDateFormat.ts 100.00% <100.00%> (ø)
...lia-slickgrid/custom-elements/aurelia-slickgrid.ts 0.00% <0.00%> (-100.00%) ⬇️

... and 6 files with indirect coverage changes

@ghiscoding
Copy link
Owner

ghiscoding commented Sep 23, 2023

@MaximBalaganskiy
I got a lot further with the migration and now have all Examples working and all Cypress E2E tests passing, I'm still missing 90% of Jest unit tests but I can fix that later. The main problem I'm getting now is with the WebPack production build, it's not working as I expect to be. After a WebPack prod build, I like to use servor which is a small http server for making sure the prod build is working as it should. However it doesn't work with this new WebPack config for Aurelia 2.

At first, I got this error

webpack : Uncaught ReferenceError: require is not defined
which as this Stack Overflow answer suggest, we shouldn't be using nodeExternals() in a prod build, and if I comment that out then the build works without error but nothing shows in servor.

Do you have a working setup for a production build? I'm pretty sure that it has to work with my servor little server, if it doesn't then the GitHub demo page won't work either. Any chance you can help with this? For now, I'll use WebPack in dev mode to run CI E2E tests... Note that I also tried my Au1 WebPack config but that doesn't at all with Au2

@MaximBalaganskiy
Copy link
Collaborator Author

The prod build only builds a plugin, what are you serving after it?

@ghiscoding
Copy link
Owner

ghiscoding commented Sep 23, 2023

The prod build only builds a plugin, what are you serving after it?

@MaximBalaganskiy The build for publishing the lib on npm is a separate process, what I want to fix is the website build for the GitHub demo page and also for the CI

@ghiscoding
Copy link
Owner

The prod build only builds a plugin, what are you serving after it?

ohhhh I see what you mean now, I was not using WebPack for the plugin build in Au1 but it looks you are in Au2, I did not noticed that. I was using TypeScript build previously, would that still work or should I really need to use WebPack for the plugin build?

Anyway, here is what I modified in WebPack to get the website demo working as I wanted.

image

As I mentioned in previous paragraph, I was using simple TypeScript scripts to build the plugin, could I still use these scripts or should I really use WebPack to build the plugin?

"build:amd": "tsc --project src/aurelia-slickgrid/tsconfig.build.json --outDir dist/amd --module amd",
"postbuild:amd": "copyfiles --up 2 src/aurelia-slickgrid/**/*.html dist/amd",
"build:commonjs": "tsc --project src/aurelia-slickgrid/tsconfig.build.json --outDir dist/commonjs --module commonjs",
"postbuild:commonjs": "copyfiles --up 2 src/aurelia-slickgrid/**/*.html dist/commonjs",
"build:esm": "tsc --project src/aurelia-slickgrid/tsconfig.build.json --outDir dist/esm --module esnext --target es2018",
"postbuild:esm": "copyfiles --up 2 src/aurelia-slickgrid/**/*.html dist/esm",
"build:native-modules": "tsc --project src/aurelia-slickgrid/tsconfig.build.json --outDir dist/native-modules --module es2015",
"postbuild:native-modules": "copyfiles --up 2 src/aurelia-slickgrid/**/*.html dist/native-modules",

@ghiscoding ghiscoding merged commit ab8e29d into ghiscoding:next Sep 27, 2023
2 checks passed
@ghiscoding
Copy link
Owner

ghiscoding commented Sep 27, 2023

I think it's time to merge since this PR is starting to be quite large already, however the Aurelia-Slickgrid component unit test is entirely missing, I seem to have problem running the unit tests for that one in particular but that can be added in the future (or skipped entirely, it doesn't make much difference on the usage since all Cypress E2E tests are passing).

Please note however that a new major release is still a month or two away since there need to be a major restructure in the Slickgrid-Universal project that I need to work on next.

Thanks a lot @MaximBalaganskiy for all of this, I would not have been able to migrate without your help, so thanks a lot!!!

@MaximBalaganskiy
Copy link
Collaborator Author

No problem, I wasn't expecting such a quick upgrade anyway. Nice to know that it will definitely happen now.
Thanks for your commitment!

@ghiscoding
Copy link
Owner

Hey so I just wanted to give an update on the Aurelia 2 upgrade, I'm still working on the next major version of Slickgrid-Universal and it took me much longer than expected but anyway I'm pretty sure that I'll be done in the next couple weeks (before Christmas for sure), for more info on what is left to, you can take a look at the Slickgrid-Universal Roadmap 4.0. Cheers

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

Successfully merging this pull request may close these issues.

None yet

2 participants