Major update to @preserves/core from old preserves package.
This commit is contained in:
parent
35c965b85d
commit
dc5c97b027
|
@ -207,14 +207,14 @@ export function expand(tree: Items, ctx: ExpansionContext): Items {
|
||||||
// TODO: untyped template
|
// TODO: untyped template
|
||||||
const sa = compilePattern(s.pattern);
|
const sa = compilePattern(s.pattern);
|
||||||
return t`withSelfDo(function (thisFacet) {
|
return t`withSelfDo(function (thisFacet) {
|
||||||
const _Facets = new __SYNDICATE__.Dictionary<__SYNDICATE__.Facet<any>>();
|
const _Facets = new __SYNDICATE__.Dictionary<any, __SYNDICATE__.Facet<any>>();
|
||||||
on asserted ${patternText(s.pattern)} => react {
|
on asserted ${patternText(s.pattern)} => react {
|
||||||
_Facets.set([${commaJoin(sa.captureBinders.map(t=>[t.id]))}], thisFacet);
|
_Facets.set([${commaJoin(sa.captureBinders.map(t=>[t.id]))}], thisFacet);
|
||||||
dataflow { } // TODO: horrible hack to keep the facet alive if no other endpoints
|
dataflow { } // TODO: horrible hack to keep the facet alive if no other endpoints
|
||||||
${s.body}
|
${s.body}
|
||||||
}
|
}
|
||||||
on retracted ${patternText(s.pattern)} => {
|
on retracted ${patternText(s.pattern)} => {
|
||||||
const ${ctx.argDecl(t, '_Key', '__SYNDICATE__.Value[]')} =
|
const ${ctx.argDecl(t, '_Key', '__SYNDICATE__.Value<any>[]')} =
|
||||||
[${commaJoin(sa.captureBinders.map(t=>[t.id]))}];
|
[${commaJoin(sa.captureBinders.map(t=>[t.id]))}];
|
||||||
_Facets.get(_Key)?._stop();
|
_Facets.get(_Key)?._stop();
|
||||||
_Facets.delete(_Key);
|
_Facets.delete(_Key);
|
||||||
|
@ -280,7 +280,7 @@ export function expand(tree: Items, ctx: ExpansionContext): Items {
|
||||||
constPaths: ${JSON.stringify(sa.constPaths)},
|
constPaths: ${JSON.stringify(sa.constPaths)},
|
||||||
constVals: [${commaJoin(sa.constVals.map(walk))}],
|
constVals: [${commaJoin(sa.constVals.map(walk))}],
|
||||||
capturePaths: ${JSON.stringify(sa.capturePaths)},
|
capturePaths: ${JSON.stringify(sa.capturePaths)},
|
||||||
callback: thisFacet.wrap((thisFacet, __Evt, ${ctx.argDecl(t, '__vs', 'Array<__SYNDICATE__.Value>')}) => {
|
callback: thisFacet.wrap((thisFacet, __Evt, ${ctx.argDecl(t, '__vs', 'Array<__SYNDICATE__.Value<any>>')}) => {
|
||||||
if (__Evt === __SYNDICATE__.Skeleton.EventType.${expectedEvt}) {
|
if (__Evt === __SYNDICATE__.Skeleton.EventType.${expectedEvt}) {
|
||||||
${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
thisFacet.scheduleScript(() => {${terminalWrap(t, s.terminal, walk(s.body))}});
|
thisFacet.scheduleScript(() => {${terminalWrap(t, s.terminal, walk(s.body))}});
|
||||||
|
@ -296,7 +296,7 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
const l = `Symbol.for(${JSON.stringify(s.label.text)})`;
|
const l = `Symbol.for(${JSON.stringify(s.label.text)})`;
|
||||||
const fns = JSON.stringify(s.fields.map(f => f.id.text));
|
const fns = JSON.stringify(s.fields.map(f => f.id.text));
|
||||||
const fs = ctx.typescript
|
const fs = ctx.typescript
|
||||||
? t`<${facetFieldObjectType(t, s.fields, t`__SYNDICATE__.Value`)}>`
|
? t`<${facetFieldObjectType(t, s.fields, t`__SYNDICATE__.Value<any>`)}, any>`
|
||||||
: '';
|
: '';
|
||||||
return t`const ${[s.label]} = __SYNDICATE__.Record.makeConstructor${fs}()(${maybeWalk(s.wireName) ?? l}, ${fns});`;
|
return t`const ${[s.label]} = __SYNDICATE__.Record.makeConstructor${fs}()(${maybeWalk(s.wireName) ?? l}, ${fns});`;
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,6 +22,6 @@
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
|
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"preserves": "0.6.2"
|
"@preserves/core": "0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
export * from 'preserves';
|
export * from '@preserves/core';
|
||||||
|
|
||||||
export * from './runtime/randomid.js';
|
export * from './runtime/randomid.js';
|
||||||
export * from './runtime/assertions.js';
|
export * from './runtime/assertions.js';
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
import { Record, RecordConstructor, AsPreserve, Value } from 'preserves';
|
import { Record, RecordConstructor, AsPreserve, Value } from '@preserves/core';
|
||||||
|
|
||||||
export class Seal {
|
export class Seal {
|
||||||
readonly contents: any;
|
readonly contents: any;
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
|
|
||||||
// Bags and Deltas (which are Bags where item-counts can be negative).
|
// Bags and Deltas (which are Bags where item-counts can be negative).
|
||||||
|
|
||||||
import { Value, Set, Dictionary } from 'preserves';
|
import { GenericEmbedded } from '@preserves/core';
|
||||||
|
import { Value, Set, Dictionary } from '@preserves/core';
|
||||||
|
|
||||||
export enum ChangeDescription {
|
export enum ChangeDescription {
|
||||||
PRESENT_TO_ABSENT = -1,
|
PRESENT_TO_ABSENT = -1,
|
||||||
|
@ -28,7 +29,7 @@ export enum ChangeDescription {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Bag {
|
export class Bag {
|
||||||
_items: Dictionary<number>;
|
_items: Dictionary<GenericEmbedded, number>;
|
||||||
|
|
||||||
constructor(s?: Set) {
|
constructor(s?: Set) {
|
||||||
this._items = new Dictionary();
|
this._items = new Dictionary();
|
||||||
|
@ -83,7 +84,7 @@ export class Bag {
|
||||||
this._items.forEach(f);
|
this._items.forEach(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot(): Dictionary<number> {
|
snapshot(): Dictionary<GenericEmbedded, number> {
|
||||||
return this._items.clone();
|
return this._items.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
// Property-based "dataflow"
|
// Property-based "dataflow"
|
||||||
|
|
||||||
import { FlexSet, FlexMap, Canonicalizer } from 'preserves';
|
import { FlexSet, FlexMap, Canonicalizer } from '@preserves/core';
|
||||||
import * as MapSet from './mapset.js';
|
import * as MapSet from './mapset.js';
|
||||||
|
|
||||||
export interface PropertyOptions<ObjectId> {
|
export interface PropertyOptions<ObjectId> {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
import { Value, fromJS, is, Set } from 'preserves';
|
import { Value, is, Set } from '@preserves/core';
|
||||||
|
|
||||||
import * as Skeleton from './skeleton.js';
|
import * as Skeleton from './skeleton.js';
|
||||||
import { Bag, ChangeDescription } from './bag.js';
|
import { Bag, ChangeDescription } from './bag.js';
|
||||||
|
@ -42,11 +42,11 @@ export type EndpointId = ActorId;
|
||||||
export type Task<T> = () => T;
|
export type Task<T> = () => T;
|
||||||
export type Script<T, Fields> = (this: Fields & DataflowObservableObject, f: Facet<Fields>) => T;
|
export type Script<T, Fields> = (this: Fields & DataflowObservableObject, f: Facet<Fields>) => T;
|
||||||
|
|
||||||
export type MaybeValue = Value | undefined;
|
export type MaybeValue = Value<any> | undefined;
|
||||||
export type EndpointSpec = { assertion: MaybeValue, analysis: Skeleton.Analysis | null };
|
export type EndpointSpec = { assertion: MaybeValue, analysis: Skeleton.Analysis | null };
|
||||||
|
|
||||||
export type ObserverCallback<Fields> =
|
export type ObserverCallback<Fields> =
|
||||||
(this: Fields, facet: Facet<Fields>, bindings: Array<Value>) => void;
|
(this: Fields, facet: Facet<Fields>, bindings: Array<Value<any>>) => void;
|
||||||
|
|
||||||
export type ObserverCallbacks<Fields> = {
|
export type ObserverCallbacks<Fields> = {
|
||||||
add?: ObserverCallback<Fields>;
|
add?: ObserverCallback<Fields>;
|
||||||
|
@ -150,7 +150,7 @@ export abstract class Dataspace {
|
||||||
|
|
||||||
applyPatch(ac: Actor, delta: Bag) {
|
applyPatch(ac: Actor, delta: Bag) {
|
||||||
// if (!delta.isEmpty()) debug('applyPatch BEGIN', ac && ac.toString());
|
// if (!delta.isEmpty()) debug('applyPatch BEGIN', ac && ac.toString());
|
||||||
let removals: Array<[number, Value]> = [];
|
let removals: Array<[number, Value<any>]> = [];
|
||||||
delta.forEach((count, a) => {
|
delta.forEach((count, a) => {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
// debug('applyPatch +', a && a.toString());
|
// debug('applyPatch +', a && a.toString());
|
||||||
|
@ -167,7 +167,7 @@ export abstract class Dataspace {
|
||||||
// if (!delta.isEmpty()) debug('applyPatch END');
|
// if (!delta.isEmpty()) debug('applyPatch END');
|
||||||
}
|
}
|
||||||
|
|
||||||
deliverMessage(m: Value, _sendingActor: Actor | null) {
|
deliverMessage(m: Value<any>, _sendingActor: Actor | null) {
|
||||||
// debug('deliverMessage', sendingActor && sendingActor.toString(), m.toString());
|
// debug('deliverMessage', sendingActor && sendingActor.toString(), m.toString());
|
||||||
this.index.deliverMessage(m);
|
this.index.deliverMessage(m);
|
||||||
// this.index.deliverMessage(m, (leaf, _m) => {
|
// this.index.deliverMessage(m, (leaf, _m) => {
|
||||||
|
@ -175,7 +175,7 @@ export abstract class Dataspace {
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustIndex(a: Value, count: number) {
|
adjustIndex(a: Value<any>, count: number) {
|
||||||
return this.index.adjustAssertion(a, count);
|
return this.index.adjustAssertion(a, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,18 +303,16 @@ export class Actor {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(a: Value) { this.pendingPatch().adjust(a, +1); }
|
assert(a: Value<any>) { this.pendingPatch().adjust(a, +1); }
|
||||||
retract(a: Value) { this.pendingPatch().adjust(a, -1); }
|
retract(a: Value<any>) { this.pendingPatch().adjust(a, -1); }
|
||||||
|
|
||||||
adhocRetract(a: Value) {
|
adhocRetract(a: Value<any>) {
|
||||||
a = fromJS(a);
|
|
||||||
if (this.adhocAssertions.change(a, -1, true) === ChangeDescription.PRESENT_TO_ABSENT) {
|
if (this.adhocAssertions.change(a, -1, true) === ChangeDescription.PRESENT_TO_ABSENT) {
|
||||||
this.retract(a);
|
this.retract(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adhocAssert(a: Value) {
|
adhocAssert(a: Value<any>) {
|
||||||
a = fromJS(a);
|
|
||||||
if (this.adhocAssertions.change(a, +1) === ChangeDescription.ABSENT_TO_PRESENT) {
|
if (this.adhocAssertions.change(a, +1) === ChangeDescription.ABSENT_TO_PRESENT) {
|
||||||
this.assert(a);
|
this.assert(a);
|
||||||
}
|
}
|
||||||
|
@ -343,17 +341,17 @@ class Patch extends Action {
|
||||||
ds.applyPatch(ac!, this.changes);
|
ds.applyPatch(ac!, this.changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
adjust(a: Value, count: number) {
|
adjust(a: Value<any>, count: number) {
|
||||||
this.changes.change(fromJS(a), count);
|
this.changes.change(a, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Message extends Action {
|
class Message extends Action {
|
||||||
readonly body: Value;
|
readonly body: Value<any>;
|
||||||
|
|
||||||
constructor(body: any) {
|
constructor(body: Value<any>) {
|
||||||
super();
|
super();
|
||||||
this.body = fromJS(body);
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
perform(ds: Dataspace, ac: Actor | null): void {
|
perform(ds: Dataspace, ac: Actor | null): void {
|
||||||
|
@ -577,7 +575,7 @@ export class Facet<Fields> {
|
||||||
|
|
||||||
addObserverEndpoint(specThunk: (facet: Facet<Fields>) => MaybeValue, callbacks: ObserverCallbacks<Fields>): Endpoint<Fields> {
|
addObserverEndpoint(specThunk: (facet: Facet<Fields>) => MaybeValue, callbacks: ObserverCallbacks<Fields>): Endpoint<Fields> {
|
||||||
const scriptify = (f?: ObserverCallback<Fields>) =>
|
const scriptify = (f?: ObserverCallback<Fields>) =>
|
||||||
f && ((facet: Facet<Fields>, vs: Array<Value>) =>
|
f && ((facet: Facet<Fields>, vs: Array<Value<any>>) =>
|
||||||
facet.scheduleScript(() => f.call(facet.fields, facet, vs)));
|
facet.scheduleScript(() => f.call(facet.fields, facet, vs)));
|
||||||
return this._addRawObserverEndpoint(specThunk, {
|
return this._addRawObserverEndpoint(specThunk, {
|
||||||
add: scriptify(callbacks.add),
|
add: scriptify(callbacks.add),
|
||||||
|
@ -667,11 +665,11 @@ export class Facet<Fields> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This alias exists because of the naive expansion done by the parser.
|
// This alias exists because of the naive expansion done by the parser.
|
||||||
_send(body: any) {
|
_send(body: Value<any>) {
|
||||||
this.send(body);
|
this.send(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
send(body: any) {
|
send(body: Value<any>) {
|
||||||
this.ensureNonFacetSetup('`send`');
|
this.ensureNonFacetSetup('`send`');
|
||||||
this.enqueueScriptAction(new Message(body));
|
this.enqueueScriptAction(new Message(body));
|
||||||
}
|
}
|
||||||
|
@ -772,7 +770,6 @@ export class Endpoint<Fields> {
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
let newSpec = this.updateFun.call(this.facet.fields, this.facet);
|
let newSpec = this.updateFun.call(this.facet.fields, this.facet);
|
||||||
if (newSpec.assertion !== void 0) newSpec.assertion = fromJS(newSpec.assertion);
|
|
||||||
if (!is(newSpec.assertion, this.spec.assertion)) {
|
if (!is(newSpec.assertion, this.spec.assertion)) {
|
||||||
this._uninstall(true);
|
this._uninstall(true);
|
||||||
this._install(newSpec);
|
this._install(newSpec);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
// Utilities for Maps of Sets
|
// Utilities for Maps of Sets
|
||||||
|
|
||||||
import { FlexSet, FlexMap, Canonicalizer } from 'preserves';
|
import { FlexSet, FlexMap, Canonicalizer } from '@preserves/core';
|
||||||
|
|
||||||
export function add<K,V>(m: FlexMap<K, FlexSet<V>>, k: K, v: V, c: Canonicalizer<V>) {
|
export function add<K,V>(m: FlexMap<K, FlexSet<V>>, k: K, v: V, c: Canonicalizer<V>) {
|
||||||
let s = m.get(k);
|
let s = m.get(k);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
import { Bytes } from 'preserves';
|
import { Bytes } from '@preserves/core';
|
||||||
import * as node_crypto from 'crypto';
|
import * as node_crypto from 'crypto';
|
||||||
|
|
||||||
export function _btoa(s: string): string {
|
export function _btoa(s: string): string {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
import { Value, Record } from 'preserves';
|
import { embed, Value } from '@preserves/core';
|
||||||
|
|
||||||
import { $Special } from './special.js';
|
import { $Special } from './special.js';
|
||||||
import { Dataspace, Facet, Actor, Endpoint, Script } from './dataspace.js';
|
import { Dataspace, Facet, Actor, Endpoint, Script } from './dataspace.js';
|
||||||
|
@ -25,7 +25,7 @@ import { ChangeDescription } from './bag.js';
|
||||||
import { EventType, Analysis } from './skeleton.js';
|
import { EventType, Analysis } from './skeleton.js';
|
||||||
import { Ground } from './ground.js';
|
import { Ground } from './ground.js';
|
||||||
|
|
||||||
export const $QuitDataspace = new $Special("quit-dataspace");
|
export const $QuitDataspace = embed(new $Special("quit-dataspace"));
|
||||||
|
|
||||||
export class NestedDataspace extends Dataspace {
|
export class NestedDataspace extends Dataspace {
|
||||||
readonly outerFacet: Facet<{}>;
|
readonly outerFacet: Facet<{}>;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
import { IdentitySet } from './idcoll.js';
|
import { IdentitySet } from './idcoll.js';
|
||||||
import { is, Value, Record, Set, Dictionary, canonicalString, RecordConstructorInfo, Tuple } from 'preserves';
|
import { is, Value, Record, Set, Dictionary, canonicalString, RecordConstructorInfo, GenericEmbedded } from '@preserves/core';
|
||||||
|
|
||||||
import { Bag, ChangeDescription } from './bag.js';
|
import { Bag, ChangeDescription } from './bag.js';
|
||||||
import { Discard, Capture } from './assertions.js';
|
import { Discard, Capture } from './assertions.js';
|
||||||
|
@ -255,7 +255,7 @@ function parseSelector(s: string): { popCount: number, index: number } {
|
||||||
|
|
||||||
class Continuation {
|
class Continuation {
|
||||||
readonly cachedAssertions: Set;
|
readonly cachedAssertions: Set;
|
||||||
readonly leafMap: Dictionary<Dictionary<Leaf>> = new Dictionary();
|
readonly leafMap: Dictionary<GenericEmbedded, Dictionary<GenericEmbedded, Leaf>> = new Dictionary();
|
||||||
|
|
||||||
constructor(cachedAssertions: Set) {
|
constructor(cachedAssertions: Set) {
|
||||||
this.cachedAssertions = cachedAssertions;
|
this.cachedAssertions = cachedAssertions;
|
||||||
|
@ -264,7 +264,7 @@ class Continuation {
|
||||||
|
|
||||||
class Leaf {
|
class Leaf {
|
||||||
readonly cachedAssertions: Set = new Set();
|
readonly cachedAssertions: Set = new Set();
|
||||||
readonly handlerMap: Dictionary<Handler> = new Dictionary();
|
readonly handlerMap: Dictionary<GenericEmbedded, Handler> = new Dictionary();
|
||||||
|
|
||||||
isEmpty(): boolean {
|
isEmpty(): boolean {
|
||||||
return this.cachedAssertions.size === 0 && this.handlerMap.size === 0;
|
return this.cachedAssertions.size === 0 && this.handlerMap.size === 0;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
// import { Observe, Outbound, Inbound, Capture, Discard } from './assertions.js';
|
// import { Observe, Outbound, Inbound, Capture, Discard } from './assertions.js';
|
||||||
// import * as Skeleton from './skeleton.js';
|
// import * as Skeleton from './skeleton.js';
|
||||||
|
|
||||||
// import { preserves, Value, Bytes, Record, Dictionary, encode, decode } from 'preserves';
|
// import { preserves, Value, Bytes, Record, Dictionary, encode, decode } from '@preserves/core';
|
||||||
|
|
||||||
// type MessageHandler = (e: Bytes) => void;
|
// type MessageHandler = (e: Bytes) => void;
|
||||||
// type ImplementationType = 'node.js' | 'browser' | 'none';
|
// type ImplementationType = 'node.js' | 'browser' | 'none';
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
import { Value } from '@syndicate-lang/core';
|
import { Embedded, Value } from '@syndicate-lang/core';
|
||||||
activate import { UIEvent, GlobalEvent, HtmlFragments, template, Anchor } from '@syndicate-lang/html';
|
activate import { UIEvent, GlobalEvent, HtmlFragments, template, Anchor } from '@syndicate-lang/html';
|
||||||
|
|
||||||
assertion type Person(id, firstName, lastName, address, age);
|
assertion type Person(id, firstName, lastName, address, age);
|
||||||
|
@ -56,7 +56,7 @@ boot {
|
||||||
spawn named 'controller' {
|
spawn named 'controller' {
|
||||||
on message GlobalEvent('table#the-table th', 'click', $e) => {
|
on message GlobalEvent('table#the-table th', 'click', $e) => {
|
||||||
send message SetSortColumn(
|
send message SetSortColumn(
|
||||||
JSON.parse(((e as unknown as Event).target as HTMLElement).dataset.column!));
|
JSON.parse(((e as Embedded<Event>).embeddedValue.target as HTMLElement).dataset.column!));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
import { randomId, Facet, Observe, FlexMap, Value, Record } from "@syndicate-lang/core";
|
import { randomId, Facet, Observe, FlexMap, Value, embed, Embedded } from "@syndicate-lang/core";
|
||||||
|
|
||||||
import * as P from "./protocol";
|
import * as P from "./protocol";
|
||||||
export * from "./protocol";
|
export * from "./protocol";
|
||||||
|
@ -52,7 +52,7 @@ export function spawnGlobalEventFactory<T>(thisFacet: Facet<T>) {
|
||||||
during Observe(P.GlobalEvent($selector: string, $eventType: string, _)) =>
|
during Observe(P.GlobalEvent($selector: string, $eventType: string, _)) =>
|
||||||
spawn named ['GlobalEvent', selector, eventType] {
|
spawn named ['GlobalEvent', selector, eventType] {
|
||||||
let sender = thisFacet.wrapExternal((thisFacet, e: Event) => {
|
let sender = thisFacet.wrapExternal((thisFacet, e: Event) => {
|
||||||
send message P.GlobalEvent(selector, eventType, e);
|
send message P.GlobalEvent(selector, eventType, embed(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
function handler(event: Event) {
|
function handler(event: Event) {
|
||||||
|
@ -81,7 +81,7 @@ export function spawnWindowEventFactory<T>(thisFacet: Facet<T>) {
|
||||||
during Observe(P.WindowEvent($eventType: string, _)) =>
|
during Observe(P.WindowEvent($eventType: string, _)) =>
|
||||||
spawn named ['WindowEvent', eventType] {
|
spawn named ['WindowEvent', eventType] {
|
||||||
let sender = thisFacet.wrapExternal((thisFacet, e: Event) => {
|
let sender = thisFacet.wrapExternal((thisFacet, e: Event) => {
|
||||||
send message P.WindowEvent(eventType, e);
|
send message P.WindowEvent(eventType, embed(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
let handler = function (event: Event) {
|
let handler = function (event: Event) {
|
||||||
|
@ -148,7 +148,7 @@ function spawnUIFragmentFactory<T>(thisFacet: Facet<T>) {
|
||||||
removeNodes();
|
removeNodes();
|
||||||
|
|
||||||
selector = newSelector;
|
selector = newSelector;
|
||||||
html = newHtml as Array<ChildNode>;
|
html = (newHtml as Embedded<Array<ChildNode>>).embeddedValue;
|
||||||
orderBy = newOrderBy;
|
orderBy = newOrderBy;
|
||||||
anchorNodes = (selector !== null) ? selectorMatch(document.body, selector) : [];
|
anchorNodes = (selector !== null) ? selectorMatch(document.body, selector) : [];
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ function spawnUIFragmentFactory<T>(thisFacet: Facet<T>) {
|
||||||
let handlerClosure: HandlerClosure;
|
let handlerClosure: HandlerClosure;
|
||||||
if (!eventRegistrations.has(key)) {
|
if (!eventRegistrations.has(key)) {
|
||||||
let sender = thisFacet.wrapExternal((thisFacet, e: Event) => {
|
let sender = thisFacet.wrapExternal((thisFacet, e: Event) => {
|
||||||
send message P.UIEvent(fragmentId, selector, eventType, e);
|
send message P.UIEvent(fragmentId, selector, eventType, embed(e));
|
||||||
});
|
});
|
||||||
function handler(event: Event) {
|
function handler(event: Event) {
|
||||||
sender(event);
|
sender(event);
|
||||||
|
@ -478,7 +478,7 @@ export class Anchor {
|
||||||
}
|
}
|
||||||
|
|
||||||
html(selector: string, html: HtmlFragments, orderBy: NodeOrderKey = ''): ReturnType<typeof P.UIFragment> {
|
html(selector: string, html: HtmlFragments, orderBy: NodeOrderKey = ''): ReturnType<typeof P.UIFragment> {
|
||||||
return P.UIFragment(this.fragmentId, selector, html.nodes(), orderBy);
|
return P.UIFragment(this.fragmentId, selector, embed(html.nodes()), orderBy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -1366,6 +1366,11 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@octokit/openapi-types" "^6.1.1"
|
"@octokit/openapi-types" "^6.1.1"
|
||||||
|
|
||||||
|
"@preserves/core@0.15.0":
|
||||||
|
version "0.15.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@preserves/core/-/core-0.15.0.tgz#55a14288442d404d20a2906b92b7a7cc9e522a18"
|
||||||
|
integrity sha512-PoEvwlqNNXpYykwkiD7KyjT6kfo78XXEMwJ5yOhOiEF6nVD167NVv801/DR7xIINtPDaDjdqBtqY/tamyzi7vA==
|
||||||
|
|
||||||
"@rollup/plugin-node-resolve@^11.0.1":
|
"@rollup/plugin-node-resolve@^11.0.1":
|
||||||
version "11.2.1"
|
version "11.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz#82aa59397a29cd4e13248b106e6a4a1880362a60"
|
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz#82aa59397a29cd4e13248b106e6a4a1880362a60"
|
||||||
|
@ -5781,11 +5786,6 @@ prelude-ls@~1.1.2:
|
||||||
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
|
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
|
||||||
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
|
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
|
||||||
|
|
||||||
preserves@0.6.2:
|
|
||||||
version "0.6.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/preserves/-/preserves-0.6.2.tgz#9102dae1e619c4d88459cd6a0d49c745bb687d1d"
|
|
||||||
integrity sha512-Hinv4i8HM9iUti4TzdFBkJOzQxn9LhcDWqbH4NgUTN39CBwwEkTEDCPMilf49OU+JEQgwvCIsfO/566j1dELUQ==
|
|
||||||
|
|
||||||
pretty-format@^26.0.0, pretty-format@^26.6.2:
|
pretty-format@^26.0.0, pretty-format@^26.6.2:
|
||||||
version "26.6.2"
|
version "26.6.2"
|
||||||
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93"
|
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93"
|
||||||
|
|
Loading…
Reference in New Issue