Early development: IFLoom can change until 1.0. What's stable
IFLoom

@ifloom/plugin-feed

Every export of @ifloom/plugin-feed and its /react subpath: its signature and its fields.

Generated from the source of @ifloom/plugin-feed and @ifloom/plugin-feed/react and its TSDoc by npm run api-docs. Each export links to the page that explains it, where one does.

@ifloom/plugin-feed

Comment

Type. Explained in Feed.

A comment on a post, one entry of a post's comments in FeedState.

import type { Comment } from '@ifloom/plugin-feed'
type Comment = {
  from: string
  text: string
}
FieldTypeOptionalDefaultDescription
fromstringThe commenter, a character's id or a name.
textstringThe comment's words, as written. The view fills in their prose tokens.

feed

Function. Explained in Feed.

Returns the feed plugin, for the game's plugins. It cooperates with the cast, which gives posters their names and faces.

Content declares feeds and posts in data.feed.feeds and data.feed.posts, and the helpers write its calls, such as feed.react('post-1', { likes: 2 }).

import { feed } from '@ifloom/plugin-feed'
function feed(): DefinedPlugin<FeedState, FeedsView>

Uses: DefinedPlugin, FeedState, FeedsView.

HelperSignatureDescription
feed.post(feedId: string, id: string, post?: { text?: string; image?: string; video?: string; likes?: number }): EffectRefReturns the feed/post effect, which posts the player's post id to the feed, with its words in place, picture, video and likes. A post id already used is left as it is.
feed.react(post: string, reaction: { likes?: number; from?: string; text?: string }): EffectRefReturns the feed/react effect, which adds likes, a comment from from, or both, to a post that has appeared.
feed.seen(feedId?: string): CommandRefReturns the feed/seen command, which marks the feed seen, or every feed when none is named.
feed.posted(gte?: number, feedId?: string): ConditionReturns the feed/posted condition, which holds once the player has made at least gte posts, to the feed or to any.

FeedDef

Type. Explained in Feed.

A feed the game declares in data.feed.feeds, such as a social app, a notice board or a paper. Posts name it in their feed.

import type { FeedDef } from '@ifloom/plugin-feed'
type FeedDef = {
  id: string
  name: string
}
FieldTypeOptionalDefaultDescription
idstringThe feed's id, unique among the game's feeds.
namestringThe feed's name.

feedsOf

Function. Explained in Feed.

Returns the game's feeds, data.feed.feeds from its content and packs, in declared order.

import { feedsOf } from '@ifloom/plugin-feed'
function feedsOf(game: Game): FeedDef[]

Uses: Game, FeedDef.

FeedState

Type. Explained in Feed.

The feeds a save keeps for the player. The plugin reads feeds and other people's posts from content, so the save keeps only what play changed.

import type { FeedState } from '@ifloom/plugin-feed'
type FeedState = {
  appeared: Record<string, number>
  own: OwnPost[]
  reactions: Record<string, { likes: number; comments: Comment[] }>
  seen: Record<string, number>
}
FieldTypeOptionalDefaultDescription
appearedRecord<string, number>The posts that have appeared, each id mapped to the turn it appeared on.
ownOwnPost[]The player's own posts, oldest first.
reactionsRecord<string, { likes: number; comments: Comment[] }>The likes and comments added to other people's posts since they appeared, by post id.
seenRecord<string, number>The number of other people's posts each feed had when the player last looked, by feed id.

FeedsView

Type. Explained in Feed.

The feeds as the player sees them, in view.plugins.feed.

import type { FeedsView } from '@ifloom/plugin-feed'
type FeedsView = {
  feeds: FeedView[]
  unread: number
}
FieldTypeOptionalDefaultDescription
feedsFeedView[]The game's feeds, in declared order.
unreadnumberThe number of unseen posts across every feed.

FeedView

Type. Explained in Feed.

A feed as the player sees it, in view.plugins.feed.feeds. Its unread counts other people's posts the player hasn't seen.

import type { FeedView } from '@ifloom/plugin-feed'
type FeedView = {
  id: string
  name: string
  posts: PostView[]
  unread: number
  seen: RenderedChoice | null
}
FieldTypeOptionalDefaultDescription
idstringThe feed's id.
namestringThe feed's name.
postsPostView[]The feed's posts, newest first, the player's own among them.
unreadnumberThe number of other people's posts in the feed the player hasn't seen. The player's own posts never count.
seenRenderedChoice | nullThe button that marks the feed seen, labelled with the feed/allSeen string. Null while nothing in it is new.

OwnPost

Type. Explained in Feed.

A post the player made with the feed/post effect, as FeedState keeps it.

import type { OwnPost } from '@ifloom/plugin-feed'
type OwnPost = {
  id: string
  feed: string
  turn: number
  text?: string
  image?: string
  video?: string
  likes: number
  comments: Comment[]
}
FieldTypeOptionalDefaultDescription
idstringThe post's id, which feed/react and feed/likes name.
feedstringThe id of the feed the post went to.
turnnumberThe turn the post was made on.
textstringyesThe post's words, as written. The view fills in their prose tokens.
imagestringyesThe post's picture, as written.
videostringyesThe post's video clip, as written.
likesnumberThe number of likes the post has.
commentsComment[]The comments on the post, oldest first.

PostDef

Type. Explained in Feed.

Someone else's post, which the game declares in data.feed.posts. It appears the first time its when holds after a command.

import type { PostDef } from '@ifloom/plugin-feed'
type PostDef = {
  id: string
  feed: string
  from: string
  when: Condition
  body: Block[]
  image?: string
  video?: string
  likes?: number
}
FieldTypeOptionalDefaultDescription
idstringThe post's id, unique among the game's posts.
feedstringThe id of the feed the post appears in.
fromstringThe poster, a character's id or any name the game's prose uses.
whenConditionThe post's condition. The post appears the first time it holds after a command, and stays.
bodyBlock[]The post's words, as blocks.
imagestringyesThe post's picture, a path in the game's art/ folder ('photo/park.jpg') or a URL.
videostringyesThe post's video clip, a path like image's, where a bare name is an .mp4. The React UI plays it like a GIF, looping and muted.
likesnumberyesThe number of likes the post has when it appears. 0 if left out.

postsOf

Function. Explained in Feed.

Returns the game's posts, data.feed.posts from its content and packs, in declared order.

import { postsOf } from '@ifloom/plugin-feed'
function postsOf(game: Game): PostDef[]

Uses: Game, PostDef.

PostView

Type. Explained in Feed.

A post as the player sees it, in a FeedView's posts.

import type { PostView } from '@ifloom/plugin-feed'
type PostView = {
  id: string
  from: string
  name: string
  portrait: string | null
  text: string
  beats: SceneBeat[]
  image: string | null
  video: string | null
  turn: number
  likes: number
  comments: { from: string; name: string; text: string }[]
  mine: boolean
}
FieldTypeOptionalDefaultDescription
idstringThe post's id.
fromstringThe poster as written, a character's id or a name. It's '' for the player's own post.
namestringThe poster's name, or for the player's own post the playerName kv key, else the feed/you string ("You").
portraitstring | nullThe poster's face for an avatar, through artSrc. It's a person's portrait with the cast, else their entity's picture. It's null for the player's own post and for a poster named only as written.
textstringThe post's words, tokens filled in, with any picture and video markup in them.
beatsSceneBeat[]The post's words rendered as beats, as a scene's are, with pictures and videos in the order written.
imagestring | nullThe post's picture's path, through artSrc, or null when it has none.
videostring | nullThe post's video clip's path, through artSrc, or null when it has none.
turnnumberThe turn the post appeared on, or was posted on.
likesnumberThe number of likes the post has, its starting likes plus any reactions.
comments{ from: string; name: string; text: string }[]The comments on the post, oldest first, each with its commenter as written, their name and its words.
minebooleanTrue for the player's own post.

@ifloom/plugin-feed/react

FEED_WORDS

Const. Explained in Feed.

The feed plugin's words in English, keyed by name. A game rewords any of them with ui.<key> in its strings.

import { FEED_WORDS } from '@ifloom/plugin-feed/react'
const FEED_WORDS: { readonly likes: '♥ {n}'; }

FeedControls

Type. Explained in Feed.

The feed plugin's view with a way to mark a feed seen, as useFeed returns it.

import type { FeedControls } from '@ifloom/plugin-feed/react'
type FeedControls = {
  feeds: FeedView[]
  unread: number
  seen: (feed: string) => Result<GameState>
}
FieldTypeOptionalDefaultDescription
feedsFeedView[]The game's feeds, in declared order.
unreadnumberThe number of unseen posts across every feed.
seen(feed: string) => Result<GameState>Sends the feed/seen command, which marks the feed's posts seen.

FeedSection

Const. Explained in Feed.

Renders the feed named by an app section's with.feed, from view.plugins.feed, newest post first. A preset styles its feed, post and post-* parts.

Each post shows its likes and comments, and a button marks the feed seen.

A post's words render as beats through Beat, and its video through Video, playing, looping and muted.

import { FeedSection } from '@ifloom/plugin-feed/react'
const FeedSection: ComponentType<SectionProps>

Uses: SectionProps.

feedUi

Const. Explained in Feed.

The feed plugin's React UI, for plugins on mountGame or GameProvider. It registers FeedSection for a device app's feed section, and adds the plugin's words.

import { feedUi } from '@ifloom/plugin-feed/react'
const feedUi: PluginUi

Uses: PluginUi.

useFeed

Function. Explained in Feed.

Returns the feed plugin's view and its command from the running game, or null in a game without the plugin. It re-renders when the view changes. FeedSection renders from it.

import { useFeed } from '@ifloom/plugin-feed/react'
function useFeed(): FeedControls | null

Uses: FeedControls.

Last updated on

On this page