-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ReplaceableComponentsService { | ||
private state: InternalStore<ReplaceableComponents.ReplaceableComponent[]>; |
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.
Store would be better naming
private state: InternalStore<ReplaceableComponents.ReplaceableComponent[]>; | |
private store: InternalStore<ReplaceableComponents.ReplaceableComponent[]>; |
} | ||
|
||
get onUpdate$(): Observable<ReplaceableComponents.ReplaceableComponent[]> { | ||
return this.state.sliceUpdate(state => state); |
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.
return this.state.sliceUpdate(state => state); | |
return this.store.sliceUpdate(state => state); |
} | ||
|
||
constructor(private ngZone: NgZone, private router: Router) { | ||
this.state = new InternalStore([]); |
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.state = new InternalStore([]); | |
this.store = new InternalStore([]); |
} | ||
|
||
add(replaceableComponent: ReplaceableComponents.ReplaceableComponent, reload?: boolean): void { | ||
let replaceableComponents = this.state.state; |
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.
let replaceableComponents = this.state.state; | |
let replaceableComponents = this.store.state; |
replaceableComponents = [...replaceableComponents, replaceableComponent]; | ||
} | ||
|
||
this.state.patch(replaceableComponents); |
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.state.patch(replaceableComponents); | |
this.store.patch(replaceableComponents); |
@@ -69,6 +56,7 @@ export class ReplaceableComponentsState { | |||
replaceableComponents, | |||
}); | |||
|
|||
if (reload) this.reloadRoute(); | |||
console.log(this.service); |
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.
console.log(this.service); |
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ReplaceableComponentsService { | ||
private state: InternalStore<ReplaceableComponents.ReplaceableComponent[]>; |
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.
private state: InternalStore<ReplaceableComponents.ReplaceableComponent[]>; | |
private state = new InternalStore<ReplaceableComponents.ReplaceableComponent[]>([]); |
} | ||
|
||
constructor(private ngZone: NgZone, private router: Router) { | ||
this.state = new InternalStore([]); |
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.state = new InternalStore([]); |
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); |
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.
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); |
npm/ng-packs/packages/core/src/lib/services/replaceable-components.service.ts
Outdated
Show resolved
Hide resolved
…ents.service.ts Co-authored-by: Levent Arman Özak <[email protected]>
npm/ng-packs/packages/core/src/lib/services/replaceable-components.service.ts
Outdated
Show resolved
Hide resolved
…ents.service.ts Co-authored-by: Bunyamin Coskuner <[email protected]>
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.
LGTM
Resolves #5026