In-App UI
JavaScript
SDK
FeedClient

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:

items.received.realtimeevent
Invoked whenever items are received in realtime from the socket.
items.received.pageevent
Invoked whenever items are received from performing a fetch. Will be invoked for the initial fetch as well.
items.received.*event
Invoked when any event with a name matching this pattern is emitted, e.g. `items.received.realtime` or `items.received.page`.
items.archivedevent
Invoked when one or more items are archived.
items.unarchivedevent
Invoked when one or more items are unarchived.
items.seenevent
Invoked when one or more items are seen.
items.unseenevent
Invoked when one or more items are unseen.
items.readevent
Invoked when one or more items are read.
items.unreadevent
Invoked when one or more items are unread.
items.all_archivedevent
Invoked when all items in the current scope are marked as archived.
items.all_seenevent
Invoked when all items in the current scope are marked as seen.
items.all_readevent
Invoked when all items in the current scope are marked as read.
items.*event
Invoked when any event with a name matching this pattern is emitted, e.g. `items.read` or `items.archived`.

Parameters:

eventNameenum of `messages.new` | `items.received.realtime` | `items.received.page` | `items.received.*`
The type of event to bind to.
callbackfunction
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:

itemOrItemsFeedItemOrItems
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:

itemOrItemsFeedItemOrItems
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:

itemOrItemsFeedItemOrItems
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:

itemOrItemsFeedItemOrItems
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:

itemOrItemsFeedItemOrItems
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:

itemOrItemsFeedItemOrItems
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:

itemOrItemsFeedItemOrItems
A single `FeedItem` or a list of `FeedItem` to perform the update on.
metadataRecord<string, any>
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:

optionsFetchFeedOptions
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.