@actualwave/weak-storage 中文文档教程
Weak Storage
具有弱引用值的键值对的映射实现。 它基于 WeakRef 规范,您可以在 Chrome 金丝雀。
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}
Weak Storage
Map implementation for key-value pairs with weak referenced values. It is based on WeakRef spec and you can try it in Chrome Canary.
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}