New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@milkdown/ctx

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@milkdown/ctx - npm Package Compare versions

Comparing version 6.2.0 to 6.3.0

src/context/shallow-clone.spec.ts

230

lib/index.es.js

@@ -1,169 +0,97 @@

var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
var w = (t, s, i) => {
if (!s.has(t))
throw TypeError("Cannot " + i);
};
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
var a = (t, s, i) => (w(t, s, "read from private field"), i ? i.call(t) : s.get(t)), u = (t, s, i) => {
if (s.has(t))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var _container, _clock, _container2, _clock2;
import { contextNotFound, ctxCallOutOfScope, timerNotFound } from "@milkdown/exception";
const createContainer = () => {
const sliceMap = /* @__PURE__ */ new Map();
const getSlice = (slice) => {
const context = typeof slice === "string" ? [...sliceMap.values()].find((x) => x.name === slice) : sliceMap.get(slice.id);
if (!context) {
const name = typeof slice === "string" ? slice : slice.sliceName;
throw contextNotFound(name);
s instanceof WeakSet ? s.add(t) : s.set(t, i);
}, h = (t, s, i, e) => (w(t, s, "write to private field"), e ? e.call(t, i) : s.set(t, i), i);
import { contextNotFound as C, ctxCallOutOfScope as S, timerNotFound as E } from "@milkdown/exception";
const N = () => {
const t = /* @__PURE__ */ new Map();
return { getSlice: (i) => {
const e = typeof i == "string" ? [...t.values()].find((n) => n.name === i) : t.get(i.id);
if (!e) {
const n = typeof i == "string" ? i : i.sliceName;
throw C(n);
}
return context;
};
return { getSlice, sliceMap };
};
const shallowClone = (x) => {
if (Array.isArray(x)) {
return [...x];
}
if (typeof x === "object") {
return __spreadValues({}, x);
}
return x;
};
const createSlice = (value, name) => {
const id = Symbol("Context");
const factory = (container, resetValue = shallowClone(value)) => {
let inner = resetValue;
const context = {
name,
id,
set: (next) => {
inner = next;
return e;
}, sliceMap: t };
}, T = (t) => Array.isArray(t) ? [...t] : typeof t == "object" ? { ...t } : t, P = (t, s) => {
const i = Symbol("Context"), e = (n, f = T(t)) => {
let o = f;
const c = {
name: s,
id: i,
set: (r) => {
o = r;
},
get: () => inner,
update: (updater) => {
inner = updater(inner);
get: () => o,
update: (r) => {
o = r(o);
}
};
container.set(id, context);
return context;
return n.set(i, c), c;
};
factory.sliceName = name;
factory.id = id;
factory._typeInfo = () => {
throw ctxCallOutOfScope();
};
return factory;
return e.sliceName = s, e.id = i, e._typeInfo = () => {
throw S();
}, e;
};
class Ctx {
constructor(container, clock) {
__privateAdd(this, _container, void 0);
__privateAdd(this, _clock, void 0);
this.use = (slice) => __privateGet(this, _container).getSlice(slice);
this.get = (slice) => this.use(slice).get();
this.set = (slice, value) => this.use(slice).set(value);
this.update = (slice, updater) => this.use(slice).update(updater);
this.timing = (timer) => __privateGet(this, _clock).get(timer);
this.wait = (timer) => this.timing(timer)();
this.done = (timer) => this.timing(timer).done();
this.waitTimers = async (slice) => {
await Promise.all(this.get(slice).map((x) => this.wait(x)));
return;
};
__privateSet(this, _container, container);
__privateSet(this, _clock, clock);
var l, d;
class k {
constructor(s, i) {
u(this, l, void 0);
u(this, d, void 0);
this.use = (e) => a(this, l).getSlice(e), this.get = (e) => this.use(e).get(), this.set = (e, n) => this.use(e).set(n), this.update = (e, n) => this.use(e).update(n), this.timing = (e) => a(this, d).get(e), this.wait = (e) => this.timing(e)(), this.done = (e) => this.timing(e).done(), this.waitTimers = async (e) => {
await Promise.all(this.get(e).map((n) => this.wait(n)));
}, h(this, l, s), h(this, d, i);
}
}
_container = new WeakMap();
_clock = new WeakMap();
class Pre {
constructor(container, clock) {
__privateAdd(this, _container2, void 0);
__privateAdd(this, _clock2, void 0);
this.inject = (ctx, defaultValue) => {
ctx(__privateGet(this, _container2).sliceMap, defaultValue);
return this;
};
this.record = (timer) => {
timer(__privateGet(this, _clock2).store);
return this;
};
__privateSet(this, _container2, container);
__privateSet(this, _clock2, clock);
l = new WeakMap(), d = new WeakMap();
var m, g;
class x {
constructor(s, i) {
u(this, m, void 0);
u(this, g, void 0);
this.inject = (e, n) => (e(a(this, m).sliceMap, n), this), this.record = (e) => (e(a(this, g).store), this), h(this, m, s), h(this, g, i);
}
}
_container2 = new WeakMap();
_clock2 = new WeakMap();
const createClock = () => {
const store = /* @__PURE__ */ new Map();
const get = (timer) => {
const meta = store.get(timer.id);
if (!meta)
throw timerNotFound();
return meta;
};
m = new WeakMap(), g = new WeakMap();
const L = () => {
const t = /* @__PURE__ */ new Map();
return {
store,
get
store: t,
get: (i) => {
const e = t.get(i.id);
if (!e)
throw E(i.name);
return e;
}
};
};
const createTimer = (name, timeout = 3e3) => {
const id = Symbol("Timer");
const timer = (store) => {
let isResolved = false;
let listener;
const data = Symbol(name);
const timing = () => isResolved ? Promise.resolve(void 0) : new Promise((resolve, reject) => {
listener = (e) => {
if (!(e instanceof CustomEvent)) {
return;
}
if (e.detail.id === data) {
isResolved = true;
resolve();
}
};
setTimeout(() => {
reject(`Timing ${name} timeout.`);
removeEventListener(name, listener);
}, timeout);
addEventListener(name, listener);
}, j = (t, s = 3e3) => {
const i = Symbol("Timer"), e = (n) => {
let f = !1, o;
const c = Symbol(t), r = () => f ? Promise.resolve(void 0) : new Promise((p, y) => {
o = (v) => {
v instanceof CustomEvent && v.detail.id === c && (f = !0, p());
}, setTimeout(() => {
y(`Timing ${t} timeout.`), removeEventListener(t, o);
}, s), addEventListener(t, o);
});
timing.done = () => {
const event = new CustomEvent(name, { detail: { id: data } });
dispatchEvent(event);
removeEventListener(name, listener);
};
store.set(id, timing);
return timing;
return r.done = () => {
const p = new CustomEvent(t, { detail: { id: c } });
dispatchEvent(p), removeEventListener(t, o);
}, n.set(i, r), r;
};
timer.id = id;
return timer;
return e.id = i, e;
};
export { Ctx, Pre, createClock, createContainer, createSlice, createTimer };
export {
k as Ctx,
x as Pre,
L as createClock,
N as createContainer,
P as createSlice,
j as createTimer
};
//# sourceMappingURL=index.es.js.map
{
"name": "@milkdown/ctx",
"version": "6.2.0",
"version": "6.3.0",
"type": "module",

@@ -23,4 +23,4 @@ "main": "./lib/index.es.js",

"dependencies": {
"@milkdown/exception": "6.2.0",
"tslib": "^2.3.1"
"@milkdown/exception": "6.3.0",
"tslib": "^2.4.0"
},

@@ -27,0 +27,0 @@ "nx": {

@@ -13,3 +13,5 @@ /* Copyright 2021, Milkdown by Mirone. */

expect(factory.sliceName).toBe('primitive');
expect(factory.id).toBeTypeOf('symbol');
expect(ctx.name).toBe('primitive');
expect(ctx.id).toBe(factory.id);

@@ -31,2 +33,3 @@ expect(ctx.get()).toBe(0);

const ctx1 = factory(map1);
expect(ctx1.id).toBe(factory.id);

@@ -39,2 +42,3 @@ expect(ctx1.name).toBe('structure');

expect(ctx2.name).toBe('structure');
expect(ctx2.id).toBe(factory.id);

@@ -41,0 +45,0 @@ expect(ctx1.get()).toEqual([]);

@@ -22,3 +22,3 @@ /* Copyright 2021, Milkdown by Mirone. */

const meta = store.get(timer.id);
if (!meta) throw timerNotFound();
if (!meta) throw timerNotFound(timer.name);
return meta;

@@ -25,0 +25,0 @@ };

@@ -16,2 +16,5 @@ /* Copyright 2021, Milkdown by Mirone. */

await expect(timing()).resolves.toBeUndefined();
// should still can be waited after it's resolved
await expect(timing()).resolves.toBeUndefined();
});

@@ -18,0 +21,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc