Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/MacFJA/svelte-expirable

A Svelte store with items that expire
https://github.com/MacFJA/svelte-expirable

Last synced: 28 days ago
JSON representation

A Svelte store with items that expire

Awesome Lists containing this project

README

        

# Svelte Expirable store

A Svelte store with items that expire

## Installation

```
npm install @macfja/svelte-expirable
```

## Usage

`notification.js`
```javascript
import { expirable } from "@macfja/svelte-expirable"

export const notifications = expirable()
```

`App.svelte`
```html

import { notifications } from './notifications.js'

const onClickHandler = () => {
// Do some action
notifications.push('Data saved', 2) // Message expire after 2 seconds
}

{#each $notifications as {data, id, repeated} (id)}

{data}{#if repeated > 0} (x{repeated + 1}){/if}

{/each}

```

When the same data is push to the store, the expiration time is reset to the new TTL, and the `repeated` variable is incremented

## Contributing

Contributions are welcome. Please open up an issue or create PR if you would like to help out.

Read more in the [Contributing file](CONTRIBUTING.md)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.