From 0d8caf06e7fe9d2bd60d7149c08d5d871176455a Mon Sep 17 00:00:00 2001 From: tpluscode Date: Mon, 3 Jan 2022 21:36:34 +0100 Subject: [PATCH] feat: rdf resource object as state --- .changeset/long-dryers-act.md | 5 +++++ packages/core/core.ts | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/long-dryers-act.md diff --git a/.changeset/long-dryers-act.md b/.changeset/long-dryers-act.md new file mode 100644 index 0000000..cc43a03 --- /dev/null +++ b/.changeset/long-dryers-act.md @@ -0,0 +1,5 @@ +--- +"@hydrofoil/shell-core": patch +--- + +Preserve entire RdfResource when set to core state diff --git a/packages/core/core.ts b/packages/core/core.ts index be2e5b8..7ce6adf 100644 --- a/packages/core/core.ts +++ b/packages/core/core.ts @@ -3,6 +3,7 @@ import { HydraClient } from 'alcaeus/alcaeus' import type { GraphPointer } from 'clownface' import type { Term } from '@rdfjs/types' import type { Store } from '@hydrofoil/shell' +import type { RdfResource } from 'alcaeus' import type { Model } from './store.js' export interface CoreState { @@ -13,7 +14,7 @@ export interface CoreState { contentResource?: { id: Term pointer?: GraphPointer - } + } | RdfResource entrypoint?: GraphPointer client?: HydraClient } @@ -24,7 +25,7 @@ declare module '@hydrofoil/shell-core/store' { } } -interface SetContentResource { +type SetContentResource = RdfResource | { id?: Term pointer: GraphPointer } @@ -44,7 +45,15 @@ const reducers = { }, } }, - setContentResource(state: CoreState, { id, pointer }: SetContentResource): CoreState { + setContentResource(state: CoreState, arg: SetContentResource): CoreState { + if ('types' in arg) { + return { + ...state, + contentResource: arg, + } + } + + const { id, pointer } = arg return { ...state, contentResource: {