Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination constants #41

Merged
merged 6 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const PAGINATION_TYPE = {
Copy link
Contributor

@benmvp benmvp Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking I'm how this would get used:

import {PAGINATION_TYPE} from 'eventbrite';

const {PAGINATION} = PAGINATION_TYPE;

That seems a bit ugly.

How about:

import {PAGINATION_TYPE} from 'eventbrite';

? Which would mean we should do:

export const PAGINATION_TYPE = 'page';
export const CONTINUATION_TYPE = 'continuation';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am good with that.

PAGINATION: 'page',
CONTINUATION: 'continuation',
};

export const PAGINATION_MAP = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are currently using this internally, I think we can abstract it a bit and add it here. I think we may need to address some of the terms, but I wanted thoughts before I went too far down this path.

[PAGINATION_TYPE.PAGINATION]: {
hasMoreItems: ({page_number: pageNumber, page_count: pageCount}) =>
pageNumber >= pageCount,
getNextPage: ({page_number: pageNumber}) => pageNumber + 1,
initialPageId: 1,
},
[PAGINATION_TYPE.CONTINUATION]: {
donePredicate: ({has_more_items: hasMoreItems}) => !hasMoreItems,
getNextPage: ({continuation}) => continuation,
initialPageId: null,
},
};
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Sdk, SdkConfig} from './types';
import request from './request';

export * from './constants';

const DEFAULT_API_URL = 'https://www.eventbriteapi.com/v3';

const eventbrite = ({
Expand Down