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

Created ReplaceableComponentsService and used it instead of ReplaceableComponentsState #5333

Merged
merged 16 commits into from
Sep 9, 2020

Conversation

mehmet-erim
Copy link
Contributor

Resolves #5026

@mehmet-erim mehmet-erim added this to the 3.2 milestone Sep 8, 2020

@Injectable({ providedIn: 'root' })
export class ReplaceableComponentsService {
private state: InternalStore<ReplaceableComponents.ReplaceableComponent[]>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Store would be better naming

Suggested change
private state: InternalStore<ReplaceableComponents.ReplaceableComponent[]>;
private store: InternalStore<ReplaceableComponents.ReplaceableComponent[]>;

}

get onUpdate$(): Observable<ReplaceableComponents.ReplaceableComponent[]> {
return this.state.sliceUpdate(state => state);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return this.state.sliceUpdate(state => state);
return this.store.sliceUpdate(state => state);

}

constructor(private ngZone: NgZone, private router: Router) {
this.state = new InternalStore([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.state = new InternalStore([]);
this.store = new InternalStore([]);

}

add(replaceableComponent: ReplaceableComponents.ReplaceableComponent, reload?: boolean): void {
let replaceableComponents = this.state.state;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let replaceableComponents = this.state.state;
let replaceableComponents = this.store.state;

replaceableComponents = [...replaceableComponents, replaceableComponent];
}

this.state.patch(replaceableComponents);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.state.patch(replaceableComponents);
this.store.patch(replaceableComponents);

@@ -69,6 +56,7 @@ export class ReplaceableComponentsState {
replaceableComponents,
});

if (reload) this.reloadRoute();
console.log(this.service);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log(this.service);


@Injectable({ providedIn: 'root' })
export class ReplaceableComponentsService {
private state: InternalStore<ReplaceableComponents.ReplaceableComponent[]>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private state: InternalStore<ReplaceableComponents.ReplaceableComponent[]>;
private state = new InternalStore<ReplaceableComponents.ReplaceableComponent[]>([]);

}

constructor(private ngZone: NgZone, private router: Router) {
this.state = new InternalStore([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.state = new InternalStore([]);

Comment on lines 46 to 58
let replaceableComponents = this.state.state;

const index = replaceableComponents.findIndex(
component => component.key === replaceableComponent.key,
);

if (index > -1) {
replaceableComponents[index] = replaceableComponent;
} else {
replaceableComponents = [...replaceableComponents, replaceableComponent];
}

this.state.patch(replaceableComponents);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let replaceableComponents = this.state.state;
const index = replaceableComponents.findIndex(
component => component.key === replaceableComponent.key,
);
if (index > -1) {
replaceableComponents[index] = replaceableComponent;
} else {
replaceableComponents = [...replaceableComponents, replaceableComponent];
}
this.state.patch(replaceableComponents);
let found = 0;
const replaceableComponents: ReplaceableComponents.ReplaceableComponent[] = [];
this.state.state.forEach(component => {
if (component.key === replaceableComponent.key) {
replaceableComponents.push(replaceableComponent);
found++;
return;
}
replaceableComponents.push(component);
});
if (!found) replaceableComponents.push(replaceableComponent);
this.state.patch(replaceableComponents);

Copy link
Contributor

@bnymncoskuner bnymncoskuner left a comment

Choose a reason for hiding this comment

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

LGTM

@armanozak armanozak merged commit c7043b3 into dev Sep 9, 2020
@armanozak armanozak deleted the feat/5026 branch September 9, 2020 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transform replaceable components from NGXS state to Angular service
3 participants