Skip to content

Commit

Permalink
feat(json-ld): can directly set status from store service
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamChelman committed Dec 2, 2024
1 parent 980b11a commit 3fc9649
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion libs/json-ld/store/services/json-ld-store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { JsonLdService } from '@cognizone/json-ld/ng-core';

import { GraphStatus } from '../models';
import { RemoveGraph, Reset, SetGraph, UpdateNode } from '../store/graph.actions';
import { RemoveGraph, Reset, SetGraph, UpdateNode, UpdateStatus } from '../store/graph.actions';
import { GRAPH_STATE_TOKEN, GraphStateModel } from '../store/graph.state';

@Injectable({
Expand Down Expand Up @@ -62,6 +62,10 @@ export class JsonLdStoreService {
);
}

setGraphStatus(rootUri: string, value: GraphStatus): void {
this.store.dispatch(new UpdateStatus(rootUri, value));
}

getNode<T extends JsonLdNode>(rootUri: string, nodeUri: string): Observable<T> {
return this.getGraph(rootUri).pipe(
map(graph => graph?.nodes?.[nodeUri] as T),
Expand Down
6 changes: 6 additions & 0 deletions libs/json-ld/store/store/graph.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export class SetGraph {
constructor(public graph: ExpandedJsonLdContainer, public graphUri: string, public status: GraphStatus = 'pristine') {}
}

export class UpdateStatus {
static readonly type: string = '[JsonLdStore] update status';

constructor(public graphUri: string, public status: GraphStatus) {}
}

export class RemoveGraph {
static readonly type: string = '[JsonLdStore] remove graph';

Expand Down
12 changes: 11 additions & 1 deletion libs/json-ld/store/store/graph.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { produce } from 'immer';
import { ExpandedJsonLdContainer } from '@cognizone/json-ld-core';

import { GraphStatus } from '../models/graph-status';
import { RemoveGraph, Reset, SetGraph, UpdateNode } from './graph.actions';
import { RemoveGraph, Reset, SetGraph, UpdateNode, UpdateStatus } from './graph.actions';

interface GraphContainer {
graph: ExpandedJsonLdContainer;
Expand Down Expand Up @@ -47,6 +47,16 @@ export class GraphState {
);
}

@Action(UpdateStatus)
updateStatus(ctx: StateContext<GraphStateModel>, { status, graphUri }: UpdateStatus): void {
ctx.setState(
produce(ctx.getState(), draft => {
if (!draft.graphs[graphUri]) return;
draft.graphs[graphUri].status = status;
})
);
}

@Action(RemoveGraph)
removeGraph(ctx: StateContext<GraphStateModel>, { rootUri }: RemoveGraph): void {
ctx.setState(
Expand Down

0 comments on commit 3fc9649

Please sign in to comment.