FeedClient reference
Complete reference for the FeedClient in the Knock JavaScript SDK.
Represents the connection between a user and a feed, including methods for interacting with the items on that feed. Also includes a stateful store that can be used to build in-app notification experiences easily. See FeedStoreState
for more on the shape of the store.
Properties#
store
#Returns: StoreApi<FeedStoreState>
Methods#
listenForUpdates
#Connects the feed instance to the realtime socket so that any new items published to the feed are received over the websocket.
Returns: void
Example:
on
#Binds an event handler to be invoked when the event is triggered.
Events:
Invoked whenever items are received in realtime from the socket.
Invoked whenever items are received from performing a fetch. Will be invoked for the initial fetch as well.
Invoked when any event with a name matching this pattern is emitted, e.g. items.received.realtime
or items.received.page
.
Invoked when one or more items are archived.
Invoked when one or more items are unarchived.
Invoked when one or more items are seen.
Invoked when one or more items are unseen.
Invoked when one or more items are read.
Invoked when one or more items are unread.
Invoked when all items in the current scope are marked as archived.
Invoked when all items in the current scope are marked as seen.
Invoked when all items in the current scope are marked as read.
Invoked when any event with a name matching this pattern is emitted, e.g. items.read
or items.archived
.
Parameters:
The type of event to bind to.
A function to be invoked when the event is triggered.
Returns: void
.
Example:
off
#Unbinds an existing event handler previously bound with on
. Use this method to cleanup bound event handlers.
Returns: void
.
getState
#Programmatically access the current FeedStoreState
.
Returns: FeedStoreState
.
markAllAsSeen
#Marks all of the items in the store optimistically as seen and performs a server-side request to mark all items on the feed in the current scope as seen. Broadcasts a items:all_seen
event.
Please note: this operation is deferred and may take some time to process all items in the feed.
Returns: Promise<ApiResponse>
markAsSeen
#Marks the given items as seen
. Will perform the operation optimistically, including updating the current metadata
in the FeedStoreState
.
Parameters:
A single FeedItem
or a list of FeedItem
to perform the update on.
Returns: Promise<ApiResponse>
markAsUnseen
#Removes the seen
status on the item or items given. Will perform the operation optimistically, including updating the current metadata
in the FeedStoreState
.
Parameters:
A single FeedItem
or a list of FeedItem
to perform the update on.
Returns: Promise<ApiResponse>
markAllAsRead
#Marks all of the items in the store optimistically as read and performs a server-side request to mark all items on the feed in the current scope as read. Broadcasts a items:all_read
event.
Please note: this operation is deferred and may take some time to process all items in the feed.
Returns: Promise<ApiResponse>
markAsRead
#Sets the read
status on the item or items given. Will perform the operation optimistically, including updating the current metadata
in the FeedStoreState
.
Parameters:
A single FeedItem
or a list of FeedItem
to perform the update on.
Returns: Promise<ApiResponse>
markAsUnread
#Removes the read
status on the item or items given. Will perform the operation optimistically, including updating the current metadata
in the FeedStoreState
.
Parameters:
A single FeedItem
or a list of FeedItem
to perform the update on.
Returns: Promise<ApiResponse>
markAllAsArchived
#Marks all of the items in the store optimistically as archived and performs a server-side request to mark all items on the feed in the current scope as archived. Broadcasts a items:all_archived
event.
Please note: this operation is deferred and may take some time to process all items in the feed.
Returns: Promise<ApiResponse>
markAsArchived
#Sets the archived
status on the item or items given. Will perform the operation optimistically, including updating the current metadata
in the FeedStoreState
. Broadcasts a items:archived
event.
Parameters:
A single FeedItem
or a list of FeedItem
to perform the update on.
Returns: Promise<ApiResponse>
markAsUnarchived
#Removes the archived
status on the item or items given. Will perform the operation optimistically, including updating the current metadata
in the FeedStoreState
.
Parameters:
A single FeedItem
or a list of FeedItem
to perform the update on.
Returns: Promise<ApiResponse>
markAsInteracted
#Sets the interacted
status on the item or items given. Will perform the operation optimistically, including updating the current metadata
in the FeedStoreState
. Broadcasts an items:interacted
event.
Parameters:
A single FeedItem
or a list of FeedItem
to perform the update on.
Additional metadata to be stored with the interaction event.
Returns: Promise<ApiResponse>
fetch
#Fetches items from the feed.
Emits items.received.page
events on a successful fetch.
Parameters:
Options to pass through to the feed request.
Returns: Promise<ApiResponse>
fetchNextPage
#Fetches the next page of the feed items (if there are any more to fetch).
Emits items.received.page
events on a successful fetch.
Note: this will apply any current feed filters and append returned items to the end of the current set of items.