Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/grevend/singleton
- Owner: grevend
- License: mit
- Created: 2021-03-15T09:03:49.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-15T06:15:09.000Z (over 2 years ago)
- Last Synced: 2024-10-05T12:24:24.270Z (4 months ago)
- Topics: bundle, deno-module, javascript, module, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/singleton
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
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
```