Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/grevend/singleton

singleton deno module
https://github.com/grevend/singleton

bundle deno-module javascript module typescript

Last synced: about 2 months ago
JSON representation

singleton deno module

Awesome Lists containing this project

README

        

# singleton

![alt text](https://img.shields.io/github/license/grevend/singleton?color=blue "License")
![alt text](https://img.shields.io/github/v/release/grevend/singleton?color=red "Release")
![alt text](https://img.shields.io/github/workflow/status/grevend/singleton/Test%20Deno%20module?label=Tests "Tests")

## Example

```typescript
const rand = singleton(Math.random);
const first = rand.getInstance();
const second = rand.getInstance(); // first === second
```

#### Changing the inner instance
```typescript
const str = singleton(() => "a");
const first = rand.getInstance(); // "a"
str.setInstance("b");
const second = rand.getInstance(); // "b", first !== second
```