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(editor): add dependency injection support in editors #33
Conversation
The current state supports editor dependencies through the Column.params property. By adding `Factory.of`, with aurelia's container, we are wrapping the creation of an editor in a function that already resolves injected dependencies at the time the grid is bound. `Factory.of` returns a function that passes any number of arguments to the editor. When Slickgrid calls `currentEditor = new useEditor({})`, the function created by `Factory.of` passes the slick grid arguments to the editor's constructor after the injected dependencies, so order matters. closes #18
return params.i18n.getLocale(); | ||
} | ||
|
||
return 'en'; |
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.
you removed this function, but what happen if the user didn't do a full setup i18n
? I can't remember what is the minimal even if you have only 1 locale to support, I think that I required to at least setup i18n
with 1 locale. You might be in a better situation to confirm since you use only 1 locale, right? I just want to make sure that there will always be a locale returned on line 100
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.
oh yeah I meant to ask you about that. I guess when I tested it I forgot that you probably set it up in your demo? I never used this library so I thought that since it returned "en" whenI removed that function that the library is smart enough to return the default language
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.
if you aren't using i18n
then what does that return? If nothing is found, it should always return 'en'
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.
yeah, if it i18n is not setup in main.ts, the currentLocale will return undefined. the new commit should fix it
@@ -189,6 +190,12 @@ export class AureliaSlickgridCustomElement { | |||
height: `${binding.gridHeight}px`, | |||
width: `${binding.gridWidth}px` | |||
}; | |||
|
|||
for (const c of this.columnDefinitions) { |
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.
could you add a simple comment on top of the for
loop to briefly describe what the loop does. This makes it easier for anyone to jump in the code at any time.
if i18n is not configured it will return undefined. we want to return 'en'
Great, tested it locally and everything works fine. In the demo, you can change the locale by going in Example 12 and switch to French then come back to both Example 3-4 and see the French text appearing in both MultipleSelect and DatePicker. Good job. I guess the only other place I currently use the |
I thought about the formatters too. To get DI into a formatter it has to turn into a class. Then when you bind it to the @inject(MyFormatter)
export class Example {
constructor(private: myFormatter) {
this.columns = [{
formatter: myFormatter.format.bind(formatter) // the format function is something i made up
}]
}
} |
Were does the |
yes, |
Ok so this is really at the App level (where the grid is created).
Thoughts on any of these? I'd like to know if number 3 makes sense but I slightly started that concept in my Angular repo for the Grouping feature. So I'd like to know if it's best approach before going too far with it. For example, this line would be removed and in that Service it would simply use DI on the Shared Service (which would already have the grid object, I think). I just hope the DI in these services won't try to read the grid object too early but I don't think that would happen. |
@jmzagorski |
I can test out my example to see if it works before updating the documentation so we can show another way to use formatters. I will put a TODO item on the contributing/doc issue so I remember to do it and it does not get lost in this closed pull request.
I think for now we can leave the formatters because they function well, and I am not familiar enough with SSR yet.
I do not think we can get DI to work with shared services that pass runtime objects such as the grid, dataview, gridOptions etc. The reason for this is looking at the
After typing all of that, number 1 would be the least amount of change, but break use of your services outside of the custom element. I would not recommend number 2. Number 3 is another good option because services should be stateless, but would required a rewrite of all service methods requiring a grid object. Hopefully this all makes sense lol. |
Thanks for this review, it's really great that you took the time to write such a detail response. You seem to like number 3 a bit more than 1, however that requires user to change their Service method call to add the extra grid object. Also how would they get this grid object? ..through the |
Yes, number 3 would have to be in version 2 and most likely they get the grid from some event or leave it exposed as a I think number 1 is just as good and didn't want to rule it out. It potentially would not add any breaking changes while fixing the multiple grid problem (i think). We would need to think of a way to expose your service methods with 1 or many grids, which is challenging if we inject the services with |
Would you mind giving a shot at it? |
Yes, I will mess around with different ways. |
@jmzagorski Did you have any Wiki update to do? |
Yes the wiki is updated under Custom Editors in https://github.com/ghiscoding/aurelia-slickgrid/wiki/Editors. Great job on the release 👍 |
The current state supports editor dependencies through the Column.params property. By adding
Factory.of
, with aurelia's container, we are wrapping the creation of an editor in a function that already resolves injected dependencies at the time the grid is bound.Factory.of
returns a function that passes any number of arguments to the editor. When Slickgrid callscurrentEditor = new useEditor({})
, the function created byFactory.of
passes the slick grid arguments to the editor's constructor after the injected dependencies, so order matters.Also I changed the
compoundDateFilter
file that was not using the injectedi18n
and using the olderparams.i18n
logic. Hopefully that is okay.closes #25