Each view has its own delegate for events from that view: loading its content
and closing its player. StorytellerStoriesRowView,
StorytellerStoriesGridView, StorytellerClipsRowView, and
StorytellerClipsGridView use the list view delegate, typed
IListViewDelegate. For events from every player, such as analytics, see
Handle global callbacks.
StorytellerClipsPlayerView and StorytellerEmbeddedClipsPlayerView use the
Clips player delegate, typed IStorytellerClipsPlayerDelegate, through the
same delegate property. It adds a callback for the back button.
Set the delegate property on the view you want to observe. Assigning a new
object replaces the view's previous delegate.
conststoryRow=newStoryteller.StorytellerStoriesRowView('stories-row-id');storyRow.delegate={// Add the callbacks you need, for example:onDataLoadComplete:(success,error,dataCount)=>{if(!success){console.error('Stories could not load.',error);}},};
Called when the view finishes loading its content:
success: true when content loaded. false when the request failed or returned no Stories or Clips.
error: an Error when success is false, otherwise null. The SDK doesn't export its error classes, so check error.message.
dataCount: the number of Stories loaded, or the number of Clips in the first page. Later Clips pages load without calling onDataLoadStarted or onDataLoadComplete. A Clips player that shows one Clip reports 1.
Called when the user taps the back button at the top of a
StorytellerClipsPlayerView or StorytellerEmbeddedClipsPlayerView whose
topLevelBackButtonEnabled is true.
The back button doesn't call onPlayerDismissed. If you don't define
onTopLevelBackTapped, the button calls window.history.back(). When
topLevelBackButtonEnabled is false or not set, the button stays hidden and
doesn't call onTopLevelBackTapped.
The Storyteller Web Showcase hides a feed module when onDataLoadComplete
reports a failure or no content, in
handleDataLoadComplete.
{"slug": "storyteller-list-view-delegate", "page_title": "Handle View Callbacks", "page_url": "StorytellerListViewDelegate/", "canonical_url": "/web/StorytellerListViewDelegate/", "markdown": "# Handle view callbacks {#implementing-storyteller-list-and-clips-player-delegate-callbacks}\n\nEach view has its own `delegate` for events from that view: loading its content\nand closing its player. `StorytellerStoriesRowView`,\n`StorytellerStoriesGridView`, `StorytellerClipsRowView`, and\n`StorytellerClipsGridView` use the list view delegate, typed\n`IListViewDelegate`. For events from every player, such as analytics, see\n[Handle global callbacks](StorytellerDelegate.md).\n\n`StorytellerClipsPlayerView` and `StorytellerEmbeddedClipsPlayerView` use the\nClips player delegate, typed `IStorytellerClipsPlayerDelegate`, through the\nsame `delegate` property. It adds a callback for the back button.\n\n## Set a view delegate {#set-a-view-delegate}\n\nSet the `delegate` property on the view you want to observe. Assigning a new\nobject replaces the view's previous delegate.\n\n```javascript\nconst storyRow = new Storyteller.StorytellerStoriesRowView('stories-row-id');\nstoryRow.delegate = {\n // Add the callbacks you need, for example:\n onDataLoadComplete: (success, error, dataCount) => {\n if (!success) {\n console.error('Stories could not load.', error);\n }\n },\n};\n```\n\n```javascript\nconst clipPlayer = new Storyteller.StorytellerClipsPlayerView(\n 'clips-player-id',\n { externalId: 'clip-external-id' }\n);\nclipPlayer.topLevelBackButtonEnabled = true;\nclipPlayer.delegate = {\n onTopLevelBackTapped: () => {\n window.history.back();\n },\n};\n```\n\nFor the Clips player views' initialization, sizing, and back button, see\n[Add a Clips player to a page](StorytellerEmbeddedClipsPlayerView.md).\n\n## Delegate callbacks {#delegate-methods}\n\nAll callbacks are optional.\n\n### onDataLoadStarted\n\n```typescript\nonDataLoadStarted?: () => void;\n```\n\nCalled when the view starts loading its Stories or Clips.\n\n### onDataLoadComplete\n\n```typescript\nonDataLoadComplete?: (success: boolean, error: Error | null, dataCount: number) => void;\n```\n\nCalled when the view finishes loading its content:\n\n- `success`: `true` when content loaded. `false` when the request failed or returned no Stories or Clips.\n- `error`: an `Error` when `success` is `false`, otherwise `null`. The SDK doesn't export its error classes, so check `error.message`.\n- `dataCount`: the number of Stories loaded, or the number of Clips in the first page. Later Clips pages load without calling `onDataLoadStarted` or `onDataLoadComplete`. A Clips player that shows one Clip reports `1`.\n\n### onPlayerDismissed\n\n```typescript\nonPlayerDismissed?: () => void;\n```\n\nCalled when a Story or Clips player opened from this view is dismissed.\n\n## Clips player delegate {#clips-player-delegate}\n\n`IStorytellerClipsPlayerDelegate` has the same callbacks as\n`IListViewDelegate`, and adds `onTopLevelBackTapped`.\n\n### onTopLevelBackTapped\n\n```typescript\nonTopLevelBackTapped?: () => void;\n```\n\nCalled when the user taps the back button at the top of a\n`StorytellerClipsPlayerView` or `StorytellerEmbeddedClipsPlayerView` whose\n`topLevelBackButtonEnabled` is `true`.\n\nThe back button doesn't call `onPlayerDismissed`. If you don't define\n`onTopLevelBackTapped`, the button calls `window.history.back()`. When\n`topLevelBackButtonEnabled` is `false` or not set, the button stays hidden and\ndoesn't call `onTopLevelBackTapped`.\n\n## Delegate interfaces\n\n```typescript\ninterface IListViewDelegate {\n onDataLoadStarted?: () => void;\n\n onDataLoadComplete?: (\n success: boolean,\n error: Error | null,\n dataCount: number\n ) => void;\n\n onPlayerDismissed?: () => void;\n}\n\ninterface IStorytellerClipsPlayerDelegate extends IListViewDelegate {\n onTopLevelBackTapped?: () => void;\n}\n```\n\nThe Storyteller Web Showcase hides a feed module when `onDataLoadComplete`\nreports a failure or no content, in\n[`handleDataLoadComplete`](https://github.com/getstoryteller/storyteller-showcase-web/blob/11.0.0/nextjs/src/components/pages/showcase/home/showcase-sdk-module/useShowcaseSdkModule.ts#L40).\n", "copy_markdown_include_header": false, "base_path": "", "ai_dir": "ai", "missing_payload_behavior": "empty"}