@istar-ts/actions 0.15.0-beta.9 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1250,10 +1250,19 @@ const parseWith = _istar_ts_core.parsePistar;
1250
1250
  function createMirrorStore(remote, options = {}) {
1251
1251
  const r = remote;
1252
1252
  const metamodel = options.metamodel;
1253
+ const metamodelFor = options.metamodelFor;
1253
1254
  const limit = options.historyLimit ?? 100;
1254
1255
  const onError = options.onError ?? (() => {});
1255
1256
  const listeners = /* @__PURE__ */ new Set();
1256
- let model = metamodel ? (0, _istar_ts_core.createEmptyModel)(void 0, { metamodel }) : (0, _istar_ts_core.createEmptyModel)();
1257
+ const parseFile = (file) => {
1258
+ const base = metamodelFor ? metamodelFor(file) : metamodel;
1259
+ return parseWith(file, {
1260
+ ...base ? { metamodel: base } : {},
1261
+ ...options.fileMetamodel ? { fileMetamodel: true } : {}
1262
+ });
1263
+ };
1264
+ const initial = options.initial;
1265
+ let model = (initial === void 0 ? void 0 : initial.elements instanceof Map ? initial : parseFile(initial)) ?? (metamodel ? (0, _istar_ts_core.createEmptyModel)(void 0, { metamodel }) : (0, _istar_ts_core.createEmptyModel)());
1257
1266
  /** The last file's `"metamodel"` block, as JSON; `undefined` before the first file. */
1258
1267
  let block;
1259
1268
  let undoDepth = 0;
@@ -1265,11 +1274,9 @@ function createMirrorStore(remote, options = {}) {
1265
1274
  let disposed = false;
1266
1275
  const parse = (file) => {
1267
1276
  const nextBlock = JSON.stringify(file[_istar_ts_core.FILE_METAMODEL_KEY] ?? null);
1268
- if (nextBlock === block) return (0, _istar_ts_core.inheritMetamodel)(model, parseWith(file, { metamodel: (0, _istar_ts_core.metamodelOf)(model) }));
1269
- const parsed = parseWith(file, {
1270
- ...metamodel ? { metamodel } : {},
1271
- ...options.fileMetamodel ? { fileMetamodel: true } : {}
1272
- });
1277
+ const root = metamodelFor?.(file);
1278
+ if (nextBlock === block && (!metamodelFor || root === (0, _istar_ts_core.metamodelOf)(model))) return (0, _istar_ts_core.inheritMetamodel)(model, parseWith(file, { metamodel: (0, _istar_ts_core.metamodelOf)(model) }));
1279
+ const parsed = parseFile(file);
1273
1280
  block = nextBlock;
1274
1281
  return parsed;
1275
1282
  };
@@ -1519,6 +1526,39 @@ function createRemoteDispatcher(port) {
1519
1526
  }
1520
1527
  };
1521
1528
  }
1529
+ /**
1530
+ * `dispatcher` as a `StoreActionDispatcher`, for a consumer that asks for its dirty state (a GLSP
1531
+ * session over a host's dispatcher, `@istar-ts/glsp`'s `IstarSharedModel`). A dispatcher that has
1532
+ * `isDirty` is returned as is (with a no-op `dispose` if it has none); one that doesn't (a
1533
+ * `createRemoteDispatcher`, a mirror's) is wrapped, its dirty state tracked from the
1534
+ * `setDirtyState` notifications it relays from then on: clean until the first one, since a remote
1535
+ * dispatcher doesn't publish the state it had before. `dispose` stops tracking and never disposes
1536
+ * the dispatcher itself, which stays its owner's (#249).
1537
+ */
1538
+ function withDirtyState(dispatcher) {
1539
+ const own = dispatcher.isDirty;
1540
+ if (typeof own === "function") {
1541
+ if (typeof dispatcher.dispose === "function") return dispatcher;
1542
+ return {
1543
+ dispatch: (action, options) => dispatcher.dispatch(action, options),
1544
+ subscribe: (listener) => dispatcher.subscribe(listener),
1545
+ isDirty: () => own.call(dispatcher),
1546
+ dispose: () => void 0
1547
+ };
1548
+ }
1549
+ let dirty = false;
1550
+ const unsubscribe = dispatcher.subscribe((action) => {
1551
+ if (action.kind === "setDirtyState") dirty = action.isDirty;
1552
+ });
1553
+ return {
1554
+ dispatch: (action, options) => dispatcher.dispatch(action, options),
1555
+ subscribe: (listener) => dispatcher.subscribe(listener),
1556
+ isDirty: () => dirty,
1557
+ dispose: () => {
1558
+ unsubscribe();
1559
+ }
1560
+ };
1561
+ }
1522
1562
  //#endregion
1523
1563
  //#region src/index.ts
1524
1564
  /** Version of the action protocol this package speaks. */
@@ -1544,5 +1584,6 @@ exports.metamodelContextText = metamodelContextText;
1544
1584
  exports.paletteFromMetamodel = paletteFromMetamodel;
1545
1585
  exports.readOnlyDispatcher = readOnlyDispatcher;
1546
1586
  exports.typeHintsFor = typeHintsFor;
1587
+ exports.withDirtyState = withDirtyState;
1547
1588
 
1548
1589
  //# sourceMappingURL=index.cjs.map