🧩
Seanime Extensions
🧩
Seanime Extensions
  • Seanime
    • Getting started
    • Core APIs
    • Changelog
  • Content Providers
    • Write, test, share
    • Anime torrent provider
    • Manga provider
    • Online streaming provider
  • Plugins
    • Introduction
    • Write, test, share
    • APIs
      • Helpers
      • Store
      • Storage
      • Database
      • AniList
      • System
        • Permissions
        • OS
        • Filepath
        • Commands
        • Buffers, I/O
        • MIME
    • UI
      • Basics
      • User Interface
        • Tray
        • Toast
        • Screen
        • Command Palette
        • Action
        • DOM
      • Anime/Library
        • Anime
        • Playback
        • Continuity
        • Auto Downloader
        • Auto Scanner
        • Filler Manager
        • External Player Link
      • Downloading
        • Downloader
        • Torrent Client
      • Other
        • Manga
        • Discord
        • MPV
    • Hooks
    • Example
  • Frequently asked
    • Feature requests
Powered by GitBook
On this page
  • When to use
  • How to use
  • Example
  1. Plugins
  2. APIs

Store

Key-value store.

PreviousHelpersNextStorage

Last updated 1 month ago

When to use

  • Create a cache

  • Share values or functions between hooks

  • Share values or functions between hooks and UI context

The values aren't persisted when your plugin is reloaded.

How to use

$store makes state sharing between runtimes possible.

$store.set("foo", "bar")
$store.get("foo")
$store.watch("foo", (value) => {})
$store.getAll() // { "foo": "bar" }
$store.remove("foo")
$store.removeAll()
$store.has("foo") // false
$store.getOrSet("foo", () => { return "bar" })
$store.values() // ["bar"]

Example

my-plugin.ts
// A simple plugin that stores the history of scan durations
function init() {
    $app.onScanCompleted((e) => {
        // Store the scanning duration (in ms)
        $store.set("scan-completed", e.duration)
        
        e.next()
    })
    
    $ui.register((ctx) => {
    
        // Callback is triggered when the value is updated
        $store.watch<number>("scan-completed", (value) => {
            const now = new Date().toISOString().replaceall(".", "_")
            $storage.set("scan-duration-history."+now, value)
            ctx.toast.info(`Scanning took ${value/1000} seconds!`)
        })
    })
}