Last Changed

Track the last time the value changed.

Usage

<script>
    import {lastChanged} from "@sveu/shared"

    const {value, timestamp} = lastChanged(7)
</script>
<script>
    import {lastChanged} from "@sveu/shared"

    const {value, timestamp} = lastChanged(7)
</script>
svelte

Example

Last changed: 5 minutes ago (1695462026353)
<script lang="ts">
    import { lastChanged, rtf } from "@sveu/shared"

    const { value, timestamp } = lastChanged(
        "world",
        +Date.now() - 1000 * 60 * 5
    )

    $: time = rtf($timestamp)
</script>

<div class="text-center">
    <input bind:value="{$value}" />

    <div>
        Last changed: <strong>{$time}</strong> <span>({$timestamp})</span>
    </div>
</div>
<script lang="ts">
    import { lastChanged, rtf } from "@sveu/shared"

    const { value, timestamp } = lastChanged(
        "world",
        +Date.now() - 1000 * 60 * 5
    )

    $: time = rtf($timestamp)
</script>

<div class="text-center">
    <input bind:value="{$value}" />

    <div>
        Last changed: <strong>{$time}</strong> <span>({$timestamp})</span>
    </div>
</div>
svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Click fold/expand code

API

Arguments

Name Description Type Required
initialValue Initial value MaybeStore<T> Yes
initialTimestamp Initial timestamp number No


Returns

Name Type
value Watchable
timestamp Readable<number>