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

[WIP] feat: rewrite of ngx-sub-form without inheritance #176

Closed
wants to merge 5 commits into from

Conversation

maxime1992
Copy link
Contributor

See commit description for more.

maxime1992 and others added 2 commits June 15, 2020 09:01
This is a major architecture change which is brought without any breaking change 😄!

We've split up the code base in 2: Old one and new one.
The old one hasn't moved at all but is now deprecated (not removed yet!).
You can keep using the old one for a bit and have a smooth/incremental update to use the new API.

Few changes that you have to note with the new API:
- Only works with Angular 9 or more
- The app needs to have Ivy activated (this is because we use `ɵmarkDirty` internally. If it ever gets removed we'll probably have to ask to provide the `ChangeDetectorRef` but we were able to around this for now!)
- We got rid of inheritance 🙌
- Form errors on a FormArray are now an object instead of an array. Previously the array contained null values on all the fields without any error. It's now an object containing only the ones with errors and you can access them using the index

Please start upgrading to the new API as soon as possible as we stop supporting the old API as of today and will remove it in a near release.

This closes #171 for the major architectural changes and also the following issues as a result:
- closes #82
- closes #86
- closes #93
- closes #133
- closes #143
- closes #144
- closes #149
- closes #160
- closes #168
@maxime1992 maxime1992 added scope: doc If anything is missing or should be clarified on the documentation scope: lib Anything related to the library itself scope: demo Anything related only to the demo effort-3: days Will take one day or more to fix/create PR-action: clean up The PR requires some clean up whether it's rebasing the commits or cleaning up some code PR-action: discuss This PR needs some discussion PR-state: WIP This PR is a work in progress type: bug/fix This is a bug or at least needs a fix type: feature This is a new feature type: refactor This is a refactor labels Jun 15, 2020
const writeValue$$: ReplaySubject<Nilable<ControlInterface>> = new ReplaySubject(1);
const registerOnChange$$: ReplaySubject<(formValue: ControlInterface | null) => void> = new ReplaySubject(1);
const registerOnTouched$$: ReplaySubject<(_: any) => void> = new ReplaySubject(1);
const setDisabledState$$: ReplaySubject<boolean> = new ReplaySubject(1);

Choose a reason for hiding this comment

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

This might be better suited to being a BehaviourSubject?

writeValue$: writeValue$$.asObservable(),
registerOnChange$: registerOnChange$$.asObservable(),
registerOnTouched$: registerOnTouched$$.asObservable(),
setDisabledState$: setDisabledState$$.asObservable(),

Choose a reason for hiding this comment

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

I think the names need to be changed to highlight these are hooks/listeners? it is weird to listen to a property prefixed with set 👀


export const patchClassInstance = (componentInstance: any, obj: Object) => {
Object.entries(obj).forEach(([key, newMethod]) => {
componentInstance[key] = newMethod;

Choose a reason for hiding this comment

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

What happens if the instance already has one of the hooks defined? is it on purpose we do not use safelyPatchClassInstance ?

@maxime1992
Copy link
Contributor Author

I'm going to close #176 in favor of #188 which is the same of except that I renamed the branch to go around the publishing error with the not supported format for the branch feat/rewrite which I renamed in the new branch to feat-rewrite.

@tyroneneill I'll keep your comments in mind before merging and have a look at some point 👍

@maxime1992 maxime1992 closed this Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort-3: days Will take one day or more to fix/create PR-action: clean up The PR requires some clean up whether it's rebasing the commits or cleaning up some code PR-action: discuss This PR needs some discussion PR-state: WIP This PR is a work in progress scope: demo Anything related only to the demo scope: doc If anything is missing or should be clarified on the documentation scope: lib Anything related to the library itself type: bug/fix This is a bug or at least needs a fix type: feature This is a new feature type: refactor This is a refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants