-
Notifications
You must be signed in to change notification settings - Fork 423
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
Remove 'columns' and 'options' object replacement on initialisation #805
Conversation
…o allow passed-in objects to be updated.
function applyDefaults(targetObj, srcObj) { | ||
for (const key in srcObj) { | ||
if (srcObj.hasOwnProperty(key)) { | ||
if (!targetObj.hasOwnProperty(key)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these nested if
could be regrouped under a single if
since there's only 1 execution logic underneath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
} | ||
|
||
if (options.enableAddRow !== args.enableAddRow) { | ||
//if (typeof args.enableAddRow !== 'undefined' && options.enableAddRow !== args.enableAddRow) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this code really have to be commented out? isn't that going to break something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, I decided it was actually redundant, but I'd have to double check. We no longer have the before and after state of the options.
@@ -6223,6 +6252,7 @@ if (typeof Slick === "undefined") { | |||
"autosizeColumn": autosizeColumn, | |||
"getOptions": getOptions, | |||
"setOptions": setOptions, | |||
"updateOptions": updateOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this new function seems oddly similar to setOptions
, do we really need 2 functions that are similar with similar names? What's the difference between these 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
covered below
I'm not sure I understand what that means, we have a lot of defaults options, are these defaults going to be skipped? If this is a breaking change then you should probably start working on the next branch that I'm on (which is currently |
This is basically as suggested by #666, but I've also applied it to my fork. Everything works exactly as it does currently, but the passed in references to Example of current way:
Example of new way:
This makes very little difference in the above scenario, but for columns it makes a big difference. I generate all grid columns from metadata and create crossreferencing dictionaries (eg. column by name) before grid itinitialisation, but because all the column objects are recreated when extending from defaults any outside references to the elements of the
With this PR, defaults are applied to the actual passed in columns object instead of creating a new one. To preserve existing behaviour, you set option We could also choose to apply this change to only the I'm happy to deal with any issues around releases. Can wait and I'll apply it later to the new v5 release. I really just wanted to get feedback and see it the tests all pass (they do). |
seems like an update by pointer, does that keep it as a pointer when updated? I'm still not sure that I understand what this PR does, I'm pretty sure that on my side in order to change the locale (current language), I use the fact that the columns are saved by references and I think that if there's no more references/pointer then that would break my code at least for the locale switching part. At least I know I tried deep cloning the columns in the past and that for sure broke my locale switching because it really needs to change value by references, if this PR kinda does what deep cloning would do then I don't think I would be able to use this new feature myself |
@6pac I updated my previous comment, it would be good if you have an answer to it. I also understand that you wanted to see if the tests passes but at the same time, I managed to fully migrate I provided all info and instructions about the new structure in #804 |
OK, I feel like this is an important change, so I'll run it down. Once you get it, you'll immediately understand exactly what this is. I'm overjoyed that you've done the TS conversion, and I'm more than happy to hand-reapply this to the new codebase. OK, so currently, we pass in an
This replaces the reference to the original object. This PR changes behaviour so that instead of replacing the Other than the reference remaining unbroken, the PR changes nothing.
This PR allows the final line to be omitted, which may seem trivial. It seems easier in principle to just have a single This is a significant, if very subtle, change in behaviour, and it is possible it might not be wanted. For example, if someone maintains a single options object and uses it to initialise multiple separate grids, they might want it to be left unchanged. This is a pretty easy problem for them to solve. The The PR also does the same thing with the elements of the The |
Yeah that was challenging to convert, mostly because it's better to migrate all these JS functions to TS Classes (also because we use them as constructor fn anyway) but I had many scope issues and had to use a lot of
ahh ok now I understand, also note that now that the code is converted to TypeScript, we see the difference a bit more since the assignment is now to
hmm I don't really like this option name though, I would prefer to see the actual behavior in the name instead of seeing legacy, and we're also starting to have too many of these legacy stuffs. So maybe something along |
I only put in As I've said, it's only really the case where code depends on the passed in variable not being changed that is breaking, and the majority of the time the passed in var is a 'burner' that's only used to initialise and is then discarded. I think it's as easy to caution people to use
if they want the old behaviour as it is to get them to use the flag. You're right about using spead or assign, I've just been stuck in ES5 for so long (supporting IE11) that I'm really not up with ES6. I read up on the new features, think 'wow, that's cool' and then instantly forget all about them :-/ |
I would prefer to keep both available but I just don't like to see legacy everywhere (for example I keep using the legacy autosize since I have my own resizer to combine it with), so having a name representing the behavior made more sense to me.
Yeah the good thing about bundler is that you can write modern code ES2023 and tell the bundle what format we want output (ES6, ES2015, ...) Also since I've merged my PR #804 on Side noteI also found out today that even though I thought our current version (v4) is supported by IE11, but it's actually not because I just found out that IE11 doesn't support template string literals (as shown on Can I Use), that is when we use ``` backtick (we started using some of them). I'm not sure if we should push fixes, by replacing them with string concatenation and push another patch release, I could also backport the large dataset scrolling throttling that I discussed yesterday. |
Does the bundler replace the backticks if we select an old version of ES? |
There's no bundler in current version, it's UglifyJS which just compresses code, there's no target to ES5 or anything of such. On the other hand with the new structure with esbuild, that is a real bundler but even then esbuild doesn't support ES5 target, it's minimum is ES2015 which is close to ES6 but without backtick conversion, IE11 is dead anyway (it's EOL since last year) so I am not interested in supporting it for our upcoming v5 but yeah we could fix the code for current v4 version, we just need to replace backtick with concatenation, the funny thing is that no one ever complained and we might have added some since v2 or v3 So when will you give a try to the new structure? You can checkout the |
Looks like you've already got started, but if that's the case with the backticks, perhaps we should make the executive decision not to support ES2015/IE11 in the latest release. I have been supporting IE11 for years, but just the last 18 months my clients have finally moved on. Perhaps the time has come ;-) |
Also, I've noted before that I have a tool that you can set up a bunch of regexes in a text file and then it will apply them to every file in a folder structure, with extension filtering. It might be possible to set up our own automated conversion of the backticks pretty easily if we do want to support ES2015. |
Not that simple, I had to do multiple commits because backtick cannot be replaced by simple string concatenation, I had issues with scope, meaning that I had to wrap the code in brackets in a few areas while this wasn't required when using string literals, basically it's not that simple and the PR is done now... so up to you if you want to go ahead or not. I do not want to support IE11 in v5 but that is in the future, however for v4 I don't care that much and I'll leave it up to you if you want to do another patch version or not. |
@6pac so I closed the PR since we shouldn't care about IE anymore, it's been EOL since June of last year. On another note, could you please think about rebasing your PR against the |
will do. just got back from holidays and busy now, but will try to rebase on the weekend |
hope the vacations was good 🍹 I now finished converting all files to TypeScript 🚀 Now the next step for me is to modify my libs to test them with these new files and do a lot of testing. So there's still a plenty of other things to do but it's coming along, see #807 for more info, cheers :) |
OK, I'm onto a rewrite of this against EDIT: perhaps a bit unclear, but what I'm asking also is how you compile the TS to JS for testing. Using node? Is this integrated into a 'build' shortcut with the editor? |
Hello Ben @6pac, so the best editor is of course Visual Studio Code, it has built-in TypeScript support so it will be easy to get started with TypeScript and you will love the intellisense that we now get with TypeScript :). I've put all the TS interfaces inside I wrote a detailed explanation of the new structure and the installation in the first major PR I made on the next branch, I would suggest you read what I wrote in this PR #804 and if you have more questions then feel free to ask, there's basically 2 steps to get started with the new structure, I would suggest to close this PR and instead create a branch from Hey while installing VSCode, you should also install at the minimum the ESLint extension (click on the little puzzle icon on the side to reveal the marketplace) so that you get intellisense for any ESLint error directly in VSCode. I'm saying this because I actually just created a PR to install TypeScript-ESLint |
This will allow passed-in
options
andcolumns
objects to be maintained and updated, rather than extending them from an empty object during initialisation, which reassigns the variable and breaks the link to the original object.Before this PR,
options
would no longer be connected to theoptions
variable inside the grid. After, it will remain connected.This could be a breaking change only if code depends on the
options
orcolumns
objects remaining unchanged, for example if they are used as an 'original state' which is to be preserved and reused later.For
columns
, the main reason for preservation of the original object would be showing/hiding. Since the introduction of thehidden
column property, this approach (which is over-complex and fragile) is able to be simplified and the existing columns shown or hidden simply by changing the property and refreshing the grid. This means this it is only ever necessary to have a single copy of the columns.There is a new option
useLegacySettingObjectConfiguration
which, if true, preserves the previous method of initialisation. This PR defaults it to false for the time being so we can Break Stuff during testing.For
options
, there is a newupdateOptions
method which can be used in place ofsetOptions
. It will trigger changes to the grid after externally updating properties of theoptions
object, and can trigger anonUpdateOptions
event, which is different to theonSetOptions event
in that it only passes the currentoptions
object rather than the before and after versions.The
columns
property already has anupdateColumns
method which was added for the same reason, to provide grid updates after external changes to column objects in thecolumns
array.@ghiscoding wanting your evaluation and approval of this PR.