feat: version 2 beta
This commit is contained in:
32
tests/adapters/mocks/user-posts-reducer.ts
Normal file
32
tests/adapters/mocks/user-posts-reducer.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { makeReducer } from "../../../libraries/reducer.ts";
|
||||
import { EventStoreFactory } from "./events.ts";
|
||||
|
||||
export const userPostReducer = makeReducer<EventStoreFactory, UserPostState>(
|
||||
(state, event) => {
|
||||
switch (event.type) {
|
||||
case "post:created": {
|
||||
state.posts.push({ id: event.stream, author: event.meta.auditor });
|
||||
state.count += 1;
|
||||
break;
|
||||
}
|
||||
case "post:removed": {
|
||||
state.posts = state.posts.filter(({ id }) => id !== event.stream);
|
||||
state.count -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return state;
|
||||
},
|
||||
() => ({
|
||||
posts: [],
|
||||
count: 0,
|
||||
}),
|
||||
);
|
||||
|
||||
type UserPostState = {
|
||||
posts: {
|
||||
id: string;
|
||||
author: string;
|
||||
}[];
|
||||
count: number;
|
||||
};
|
||||
Reference in New Issue
Block a user