mount-observer 0.0.61 → 0.0.63

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/Newish.js CHANGED
@@ -2,6 +2,7 @@ export { waitForEvent } from './waitForEvent.js';
2
2
  import { ObsAttr } from './ObsAttr.js';
3
3
  import { splitRefs } from './refid/splitRefs.js';
4
4
  import { getIsh } from './refid/getIsh.js';
5
+ import { sym } from './refid/regIsh.js';
5
6
  export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
6
7
  export class Newish {
7
8
  queue = [];
@@ -50,20 +51,18 @@ export class Newish {
50
51
  set(nv) {
51
52
  if (self.#ce === nv)
52
53
  return;
53
- console.log({ nv });
54
54
  self.queue.push(nv);
55
- self.#assignGingerly();
55
+ self.#assignGingerly(false);
56
56
  },
57
57
  enumerable: true,
58
58
  configurable: true,
59
59
  });
60
- this.#assignGingerly();
60
+ this.#assignGingerly(true);
61
61
  //attach any itemref references
62
62
  this.#attachItemrefs(enhancedElement);
63
63
  const et = ObsAttr(enhancedElement, 'itemref');
64
64
  et.addEventListener('attr-changed', this);
65
65
  this.isResolved = true;
66
- enhancedElement.dispatchEvent(new Event('ishAttached'));
67
66
  }
68
67
  #alreadyAttached = new Set();
69
68
  #attachItemrefs(enhancedElement) {
@@ -86,7 +85,11 @@ export class Newish {
86
85
  }
87
86
  }
88
87
  }
89
- async #assignGingerly() {
88
+ async #assignGingerly(fromDo) {
89
+ const actions = new Set();
90
+ if (fromDo) {
91
+ actions.add('attached');
92
+ }
90
93
  let ce = this.#ce;
91
94
  if (ce === undefined) {
92
95
  throw 500;
@@ -94,13 +97,28 @@ export class Newish {
94
97
  while (this.queue.length > 0) {
95
98
  const fi = this.queue.shift();
96
99
  //TODO: Provide support for a virtual slice of a very large list
100
+ //TODO: Maybe should check if iterable rather than an array?
97
101
  if (Array.isArray(fi)) {
98
- ce.ishList = fi;
102
+ ce[sym] = fi;
103
+ actions.add('ishListAssigned');
99
104
  }
100
105
  else {
101
106
  const { assigner } = this.#options;
102
107
  await assigner(ce, fi);
108
+ actions.add('ishAssigned');
103
109
  }
104
110
  }
111
+ const ref = this.#ref.deref();
112
+ if (ref) {
113
+ ref.dispatchEvent(new IshEvent(Array.from(actions)));
114
+ }
115
+ }
116
+ }
117
+ export class IshEvent extends Event {
118
+ actions;
119
+ static eventName = 'ish';
120
+ constructor(actions) {
121
+ super(IshEvent.eventName);
122
+ this.actions = actions;
105
123
  }
106
124
  }
package/Newish.ts CHANGED
@@ -4,6 +4,7 @@ export {waitForEvent} from './waitForEvent.js';
4
4
  import {ObsAttr} from './ObsAttr.js';
5
5
  import {splitRefs} from './refid/splitRefs.js';
6
6
  import {getIsh} from './refid/getIsh.js';
7
+ import {sym} from './refid/regIsh.js';
7
8
  export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
8
9
  export class Newish implements EventListenerObject {
9
10
  queue: Array<any> = [];
@@ -62,20 +63,18 @@ export class Newish implements EventListenerObject {
62
63
  },
63
64
  set(nv: any){
64
65
  if(self.#ce === nv) return;
65
- console.log({nv});
66
66
  self.queue.push(nv);
67
- self.#assignGingerly();
67
+ self.#assignGingerly(false);
68
68
  },
69
69
  enumerable: true,
70
70
  configurable: true,
71
71
  });
72
- this.#assignGingerly();
72
+ this.#assignGingerly(true);
73
73
  //attach any itemref references
74
74
  this.#attachItemrefs(enhancedElement);
75
75
  const et = ObsAttr(enhancedElement, 'itemref');
76
76
  et.addEventListener('attr-changed', this);
77
77
  this.isResolved = true;
78
- enhancedElement.dispatchEvent(new Event('ishAttached'));
79
78
  }
80
79
 
81
80
 
@@ -102,7 +101,11 @@ export class Newish implements EventListenerObject {
102
101
 
103
102
  }
104
103
 
105
- async #assignGingerly(){
104
+ async #assignGingerly(fromDo: boolean){
105
+ const actions = new Set<Action>();
106
+ if(fromDo){
107
+ actions.add('attached');
108
+ }
106
109
  let ce = this.#ce!;
107
110
  if(ce === undefined){
108
111
  throw 500;
@@ -110,15 +113,38 @@ export class Newish implements EventListenerObject {
110
113
  while(this.queue.length > 0 ){
111
114
  const fi = this.queue.shift();
112
115
  //TODO: Provide support for a virtual slice of a very large list
116
+ //TODO: Maybe should check if iterable rather than an array?
113
117
  if(Array.isArray(fi)){
114
- (<any>ce).ishList = fi;
118
+ (<any>ce)[sym] = fi;
119
+ actions.add('ishListAssigned');
115
120
  }else{
116
121
  const {assigner} = this.#options;
117
122
  await assigner!(ce, fi);
118
-
123
+ actions.add('ishAssigned');
119
124
  }
120
125
 
121
126
  }
127
+ const ref = this.#ref.deref();
128
+ if(ref){
129
+ ref.dispatchEvent(new IshEvent(Array.from(actions)));
130
+ }
122
131
  }
123
132
 
124
133
  }
134
+
135
+ type Action =
136
+ | 'attached'
137
+ | 'ishAssigned'
138
+ | 'ishListAssigned'
139
+
140
+ interface IIshEvent{
141
+ actions: Array<Action>;
142
+ }
143
+
144
+ export class IshEvent extends Event implements IIshEvent{
145
+ static eventName = 'ish';
146
+
147
+ constructor(public actions: Array<Action>){
148
+ super(IshEvent.eventName);
149
+ }
150
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
package/refid/regIsh.js CHANGED
@@ -10,5 +10,17 @@ export function regIsh(scope, name, ctr) {
10
10
  throw 403;
11
11
  }
12
12
  map.set(name, ctr);
13
+ ctr.prototype[Symbol.iterator] = function () {
14
+ var index = -1;
15
+ var data = this[sym];
16
+ return {
17
+ next: function () {
18
+ return {
19
+ value: data === undefined ? undefined : data[++index],
20
+ done: data === undefined || !(index in data)
21
+ };
22
+ }
23
+ };
24
+ };
13
25
  document.dispatchEvent(new Event(guid));
14
26
  }
package/refid/regIsh.ts CHANGED
@@ -12,5 +12,18 @@ export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr
12
12
  throw 403;
13
13
  }
14
14
  map.set(name, ctr);
15
+ ctr.prototype[Symbol.iterator] = function() {
16
+ var index = -1;
17
+ var data = this[sym];
18
+
19
+ return {
20
+ next: function() {
21
+ return {
22
+ value: data === undefined ? undefined : data[++index],
23
+ done: data === undefined || !(index in data)
24
+ }
25
+ }
26
+ };
27
+ };
15
28
  document.dispatchEvent(new Event(guid));
16
29
  }
@@ -157,6 +157,11 @@ export type ScopeInstructions<TProps=any, TMethods=TProps> =
157
157
  | ScopingConfig
158
158
  ;
159
159
 
160
+ export interface ScopedLoop<TProps = any, TMethods = TProps>{
161
+ config?: IshConfig<TProps, TMethods>;
162
+ options: Partial<Clone$Options>
163
+ }
164
+
160
165
  export type WhereConditions =
161
166
  | string //css matches
162
167
  | {
@@ -326,6 +331,8 @@ export interface UnitOfWork<TProps, TMethods = TProps, TElement = {}>{
326
331
  y?: number | YieldSettings<TProps>,
327
332
 
328
333
  $?: ScopeInstructions<TProps, TMethods>,
334
+
335
+ $$?: ScopedLoop<TProps, TMethods>,
329
336
  }
330
337
 
331
338
  export interface YieldSettings<TProps>{
@@ -546,4 +553,15 @@ export type ZeroOrMore<T> = T | Array<T> | undefined;
546
553
  */
547
554
  export type StringWithAutocompleteOptions<TOptions> =
548
555
  | (string & {})
549
- | TOptions;
556
+ | TOptions;
557
+
558
+ export interface Clone$Options{
559
+ ish: EventTarget & HasIshList
560
+ seedEl: Element,
561
+ idxStart: number,
562
+ itemProp: string,
563
+ mapIdxTo?: string,
564
+ itemTemplate: HTMLTemplateElement;
565
+ baseCrumb: string,
566
+ idleTimeout: number,
567
+ }
package/waitForIsh.js CHANGED
@@ -7,7 +7,7 @@ export function waitForIsh(el) {
7
7
  }
8
8
  else {
9
9
  // If the element is not yet defined, wait for it to be defined
10
- el.addEventListener('ishAttached', () => {
10
+ el.addEventListener('ish', () => {
11
11
  const ish = el['ish'];
12
12
  if (ish) {
13
13
  resolve(ish);
package/waitForIsh.ts CHANGED
@@ -6,7 +6,7 @@ export function waitForIsh(el: Element) : Promise<EventTarget> {
6
6
  resolve(ish);
7
7
  } else {
8
8
  // If the element is not yet defined, wait for it to be defined
9
- el.addEventListener('ishAttached', () => {
9
+ el.addEventListener('ish', () => {
10
10
  const ish = (<any>el)['ish'] as EventTarget;
11
11
  if (ish) {
12
12
  resolve(ish);