https://github.com/burdiuz/js-weak-storage
WeakStorage is a map object based on WeakRef proposal https://github.com/tc39/proposal-weakrefs
https://github.com/burdiuz/js-weak-storage
Last synced: 2 months ago
JSON representation
WeakStorage is a map object based on WeakRef proposal https://github.com/tc39/proposal-weakrefs
- Host: GitHub
- URL: https://github.com/burdiuz/js-weak-storage
- Owner: burdiuz
- License: mit
- Created: 2020-05-03T16:07:11.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T15:59:08.000Z (over 2 years ago)
- Last Synced: 2024-10-11T00:38:29.357Z (8 months ago)
- Language: JavaScript
- Size: 1.81 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Weak Storage
Map implementation for key-value pairs with weak referenced values. It is based on [WeakRef](https://github.com/tc39/proposal-weakrefs) spec and you can try it in [Chrome Canary](https://www.google.com/chrome/canary/).```javascript
let key = {type: 'key1'};
let value = {type: 'value1'};
const storage = new WeakStorage();
storage.set(key, value);
storage.get(key); // {type: "value1"}
storage.getKey(value); // {type: "key1"}
storage.forEach(console.log) // {type: "value1"} {type: "key1"} WeakStorage{}const keys = storage.keys();
keys.next(); // { done: false, value: {type: "key1"} }
keys.next(); // {done: true, value: undefined}
keys[Symbol.iterator]().next(); // { done: false, value: {type: "key1"} }const values = storage.values();
values.next(); // { done: false, value: {type: "value1"} }
values.next(); // {done: true, value: undefined}const entries = storage.entries();
entries.next(); // { done: false, value: [ {type: "key1"}, {type: "value1"} ] }
entries.next(); // {done: true, value: undefined}
```