Skip to content

Commit

Permalink
docs: Add benchmark for Collections
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Dec 18, 2023
1 parent 604502e commit ba08a63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/benchmark/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ProjectWithBuildTypesDescriptionSimpleMerge,
ProjectQuerySorted,
User,
ProjectSchemaCollection,
} from './schemas.js';
import userData from './user.json' assert { type: 'json' };

Expand All @@ -25,6 +26,12 @@ export default function addReducerSuite(suite) {
return '/fake';
},
});
const getProjectCollection = new Endpoint(() => Promise.resolve(data), {
schema: ProjectSchemaCollection,
key() {
return '/fakeCollection';
},
});
// eslint-disable-next-line no-unused-vars
const getUser = new Endpoint(login => Promise.resolve(userData), {
schema: User,
Expand Down Expand Up @@ -55,6 +62,18 @@ export default function addReducerSuite(suite) {
reducer(state, action);
};

// setLongCollection
const controllerCollection = new Controller({});
const reducerCollection = createReducer(controllerCollection);
let collectionState = state;
controllerCollection.dispatch = action => {
collectionState = reducerCollection(state, action);
};
controllerCollection.setResponse(getProjectCollection, data);
controllerCollection.dispatch = action => {
reducerCollection(collectionState, action);
};

// setLongWithMerge
const controllerPop = new Controller({});
const reducerPop = createReducer(controllerPop);
Expand Down Expand Up @@ -116,6 +135,12 @@ export default function addReducerSuite(suite) {
.add('getResponse Query-sorted', () => {
return controller.getResponse(ProjectQuerySorted, cachedState);
})
.add('getResponse Collection', () => {
return controllerCollection.getResponse(
getProjectCollection,
collectionState,
);
})
.add('setLong', () => {
return controller.setResponse(getProject, data);
})
Expand Down
3 changes: 3 additions & 0 deletions examples/benchmark/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export const ProjectWithBuildTypesDescriptionEntity = schema.Entity(
export const ProjectSchema = {
project: [ProjectWithBuildTypesDescription],
};
export const ProjectSchemaCollection = {
project: new schema.Collection([ProjectWithBuildTypesDescription]),
};
export const ProjectSchemaMixin = {
project: [ProjectWithBuildTypesDescriptionEntity],
};
Expand Down

0 comments on commit ba08a63

Please sign in to comment.