Skip to content

Commit

Permalink
Start to redefine the contract between viewmodel construction and ren…
Browse files Browse the repository at this point in the history
…dering #3334
  • Loading branch information
kevinrutherford committed Jun 18, 2024
1 parent 2b8f329 commit 85d22a3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Json } from 'fp-ts/Json';
import * as O from 'fp-ts/Option';
import * as RA from 'fp-ts/ReadonlyArray';
import { pipe } from 'fp-ts/function';
import { ViewModel } from './view-model';
import { Queries } from '../../../../read-models';

export const constructViewModel = (queries: Queries): Json => ({
export const constructViewModel = (queries: Queries): ViewModel => ({
groups: pipe(
queries.getAllGroups(),
RA.map((group) => ({
Expand Down
5 changes: 1 addition & 4 deletions src/read-side/non-html-views/api/groups/groups.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Json } from 'fp-ts/Json';
import * as TE from 'fp-ts/TaskEither';
import { pipe } from 'fp-ts/function';
import { constructViewModel } from './construct-view-model';
import { renderAsJson } from './render-as-json';
import { Queries } from '../../../../read-models';
import { NonHtmlView } from '../../non-html-view';
import { NonHtmlViewRepresentation, toNonHtmlViewRepresentation } from '../../non-html-view-representation';

const renderAsJson = (viewModel: Json): NonHtmlViewRepresentation => toNonHtmlViewRepresentation(viewModel, 'application/json');

export const groups = (queries: Queries): NonHtmlView => () => pipe(
constructViewModel(queries),
Expand Down
4 changes: 4 additions & 0 deletions src/read-side/non-html-views/api/groups/render-as-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ViewModel } from './view-model';
import { NonHtmlViewRepresentation, toNonHtmlViewRepresentation } from '../../non-html-view-representation';

export const renderAsJson = (viewModel: ViewModel): NonHtmlViewRepresentation => toNonHtmlViewRepresentation(viewModel, 'application/json');
5 changes: 5 additions & 0 deletions src/read-side/non-html-views/api/groups/view-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Json } from 'fp-ts/Json';

export type ViewModel = {
groups: Json,
};

0 comments on commit 85d22a3

Please sign in to comment.