use numbers instead of symbols

pull/11915/head
Rich Harris 2 years ago
parent e2a0f416f7
commit 0207e3af60

@ -1,7 +1,6 @@
import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js';
import { UNINITIALIZED } from '../constants.js';
import { increment } from './utils.js';
/**
@ -10,7 +9,7 @@ import { increment } from './utils.js';
* @extends {Map<K, V>}
*/
export class ReactiveMap extends Map {
/** @type {Map<K, import('#client').Source<symbol>>} */
/** @type {Map<K, import('#client').Source<number>>} */
#sources = new Map();
#version = source(0);
#size = source(0);
@ -32,10 +31,6 @@ export class ReactiveMap extends Map {
}
}
#increment_version() {
set(this.#version, this.#version.v + 1);
}
/** @param {K} key */
has(key) {
var sources = this.#sources;
@ -44,7 +39,7 @@ export class ReactiveMap extends Map {
if (s === undefined) {
var ret = super.get(key);
if (ret !== undefined) {
s = source(Symbol());
s = source(0);
sources.set(key, s);
} else {
// We should always track the version in case
@ -76,7 +71,7 @@ export class ReactiveMap extends Map {
if (s === undefined) {
var ret = super.get(key);
if (ret !== undefined) {
s = source(Symbol());
s = source(0);
sources.set(key, s);
} else {
// We should always track the version in case
@ -101,11 +96,11 @@ export class ReactiveMap extends Map {
var res = super.set(key, value);
if (s === undefined) {
sources.set(key, source(Symbol()));
sources.set(key, source(0));
set(this.#size, super.size);
increment(this.#version);
} else if (prev_res !== value) {
set(s, Symbol());
increment(s);
}
return res;
@ -120,7 +115,7 @@ export class ReactiveMap extends Map {
if (s !== undefined) {
sources.delete(key);
set(this.#size, super.size);
set(s, UNINITIALIZED);
set(s, -1);
increment(this.#version);
}
@ -133,7 +128,7 @@ export class ReactiveMap extends Map {
if (super.size !== 0) {
set(this.#size, 0);
for (var s of sources.values()) {
set(s, UNINITIALIZED);
set(s, -1);
}
increment(this.#version);
sources.clear();
@ -148,7 +143,7 @@ export class ReactiveMap extends Map {
if (this.#size.v !== sources.size) {
for (var key of super.keys()) {
if (!sources.has(key)) {
sources.set(key, source(Symbol()));
sources.set(key, source(0));
}
}
}

Loading…
Cancel
Save