mount-observer 0.0.62 → 0.0.64

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 { arr } from './refid/secretKeys.js';
5
6
  export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
6
7
  export class Newish {
7
8
  queue = [];
@@ -25,19 +26,29 @@ export class Newish {
25
26
  if (enhancedElement[attached] === true)
26
27
  return;
27
28
  enhancedElement[attached] = true;
28
- const ctr = await getIsh(enhancedElement.isConnected ? enhancedElement : target, itemscope);
29
- const initPropVals = enhancedElement['ish'];
30
- if (enhancedElement instanceof HTMLElement) {
31
- if (enhancedElement.dataset.ish) {
32
- const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
33
- this.queue.push(parsedHostProps);
34
- }
29
+ const options = this.#options;
30
+ const { initPropVals, ctr } = options;
31
+ let ce;
32
+ if (ctr === undefined) {
33
+ const foundCtr = await getIsh(enhancedElement.isConnected ? enhancedElement : target, itemscope);
34
+ const initPropVals = enhancedElement['ish'];
35
+ // if(enhancedElement instanceof HTMLElement){
36
+ // if(enhancedElement.dataset.ish){
37
+ // const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
38
+ // this.queue.push(parsedHostProps);
39
+ // }
40
+ // }
41
+ const resolvedConstructor = foundCtr.constructor.name === 'AsyncFunction' ? await foundCtr() : foundCtr;
42
+ const isInstance = initPropVals instanceof resolvedConstructor;
43
+ ce = isInstance ? initPropVals : new resolvedConstructor();
44
+ if (initPropVals !== undefined && !isInstance)
45
+ this.queue.push(initPropVals);
46
+ }
47
+ else {
48
+ ce = new ctr();
49
+ if (initPropVals !== undefined)
50
+ this.queue.push(initPropVals);
35
51
  }
36
- const resolvedConstructor = ctr.constructor.name === 'AsyncFunction' ? await ctr() : ctr;
37
- const isInstance = initPropVals instanceof resolvedConstructor;
38
- const ce = isInstance ? initPropVals : new resolvedConstructor();
39
- if (initPropVals !== undefined && !isInstance)
40
- this.queue.push(initPropVals);
41
52
  if ('<mount>' in ce && typeof ce['<mount>'] === 'function') {
42
53
  await ce['<mount>'](ce, enhancedElement, this.#options);
43
54
  }
@@ -96,8 +107,13 @@ export class Newish {
96
107
  while (this.queue.length > 0) {
97
108
  const fi = this.queue.shift();
98
109
  //TODO: Provide support for a virtual slice of a very large list
110
+ //TODO: Maybe should check if iterable rather than an array?
99
111
  if (Array.isArray(fi)) {
100
- ce.ishList = fi;
112
+ let filtered = fi;
113
+ if ('arr=>' in ce && typeof ce['arr=>'] === 'function') {
114
+ filtered = await ce['arr=>'](ce, fi, this.#options);
115
+ }
116
+ ce[arr] = filtered;
101
117
  actions.add('ishListAssigned');
102
118
  }
103
119
  else {
package/Newish.ts CHANGED
@@ -1,14 +1,15 @@
1
- import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
1
+ import { BindishOptions, Ishcycle } from './ts-refs/mount-observer/types.js';
2
2
 
3
3
  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 {arr} from './refid/secretKeys.js';
7
8
  export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
8
9
  export class Newish implements EventListenerObject {
9
10
  queue: Array<any> = [];
10
11
  isResolved = false;
11
- #ce: HTMLElement | undefined;
12
+ #ce: Ishcycle | undefined;
12
13
  #ref: WeakRef<Element>;
13
14
 
14
15
  //#assigner: undefined | Assigner = undefined;
@@ -34,21 +35,31 @@ export class Newish implements EventListenerObject {
34
35
  ){
35
36
  if((<any>enhancedElement)[attached] === true) return;
36
37
  (<any>enhancedElement)[attached] = true;
37
- const ctr = await getIsh(enhancedElement.isConnected ? enhancedElement :target, itemscope)! as any;
38
-
39
- const initPropVals = (<any>enhancedElement)['ish'];
40
- if(enhancedElement instanceof HTMLElement){
41
- if(enhancedElement.dataset.ish){
42
- const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
43
- this.queue.push(parsedHostProps);
44
- }
38
+ const options = this.#options;
39
+ const {initPropVals, ctr} = options;
40
+ let ce: Ishcycle;
41
+ if(ctr === undefined){
42
+ const foundCtr = await getIsh(enhancedElement.isConnected ? enhancedElement :target, itemscope)! as any;
43
+
44
+ const initPropVals = (<any>enhancedElement)['ish'];
45
+ // if(enhancedElement instanceof HTMLElement){
46
+ // if(enhancedElement.dataset.ish){
47
+ // const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
48
+ // this.queue.push(parsedHostProps);
49
+ // }
50
+ // }
51
+
52
+
53
+ const resolvedConstructor = foundCtr.constructor.name === 'AsyncFunction' ? await foundCtr() : foundCtr;
54
+ const isInstance = initPropVals instanceof resolvedConstructor
55
+ ce = isInstance ? initPropVals : new resolvedConstructor() as Ishcycle;
56
+ if(initPropVals !== undefined && !isInstance) this.queue.push(initPropVals);
57
+ }else{
58
+ ce = new ctr();
59
+ if(initPropVals !== undefined) this.queue.push(initPropVals);
45
60
  }
46
-
47
-
48
- const resolvedConstructor = ctr.constructor.name === 'AsyncFunction' ? await ctr() : ctr;
49
- const isInstance = initPropVals instanceof resolvedConstructor
50
- const ce = isInstance ? initPropVals : new resolvedConstructor();
51
- if(initPropVals !== undefined && !isInstance) this.queue.push(initPropVals);
61
+
62
+
52
63
 
53
64
  if('<mount>' in ce && typeof ce['<mount>'] === 'function'){
54
65
  await ce['<mount>'](ce, enhancedElement, this.#options)
@@ -112,8 +123,13 @@ export class Newish implements EventListenerObject {
112
123
  while(this.queue.length > 0 ){
113
124
  const fi = this.queue.shift();
114
125
  //TODO: Provide support for a virtual slice of a very large list
126
+ //TODO: Maybe should check if iterable rather than an array?
115
127
  if(Array.isArray(fi)){
116
- (<any>ce).ishList = fi;
128
+ let filtered = fi;
129
+ if('arr=>' in ce && typeof ce['arr=>'] === 'function'){
130
+ filtered = await ce['arr=>'](ce, fi, this.#options);
131
+ }
132
+ (<any>ce)[arr] = filtered;
117
133
  actions.add('ishListAssigned');
118
134
  }else{
119
135
  const {assigner} = this.#options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
package/refid/regIsh.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export const guid = 'La8Cx9vHsUOd03WomqdnPw';
2
2
  export const sym = Symbol.for(guid);
3
+ import { arr } from './secretKeys.js';
3
4
  export function regIsh(scope, name, ctr) {
4
5
  let map = scope[sym];
5
6
  if (map === undefined) {
@@ -10,5 +11,17 @@ export function regIsh(scope, name, ctr) {
10
11
  throw 403;
11
12
  }
12
13
  map.set(name, ctr);
14
+ ctr.prototype[Symbol.iterator] = function () {
15
+ var index = -1;
16
+ var data = this[arr];
17
+ return {
18
+ next: function () {
19
+ return {
20
+ value: data === undefined ? undefined : data[++index],
21
+ done: data === undefined || !(index in data)
22
+ };
23
+ }
24
+ };
25
+ };
13
26
  document.dispatchEvent(new Event(guid));
14
27
  }
package/refid/regIsh.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {IshCtr} from '../ts-refs/mount-observer/types';
2
2
  export const guid = 'La8Cx9vHsUOd03WomqdnPw'
3
3
  export const sym = Symbol.for(guid);
4
+ import {arr} from './secretKeys.js';
4
5
 
5
6
  export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr:IshCtr){
6
7
  let map = (<any>scope)[sym] as Map<string, IshCtr>;
@@ -12,5 +13,18 @@ export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr
12
13
  throw 403;
13
14
  }
14
15
  map.set(name, ctr);
16
+ ctr.prototype[Symbol.iterator] = function() {
17
+ var index = -1;
18
+ var data = this[arr];
19
+
20
+ return {
21
+ next: function() {
22
+ return {
23
+ value: data === undefined ? undefined : data[++index],
24
+ done: data === undefined || !(index in data)
25
+ }
26
+ }
27
+ };
28
+ };
15
29
  document.dispatchEvent(new Event(guid));
16
30
  }
@@ -0,0 +1,5 @@
1
+ //using Symbol.for, which is easily hackaable, because if two different entry points
2
+ //come from different versions of mount-observer, things could get out of sync.
3
+ //Not an issue if this was built into the browser, but it is an issue for a custom a library.
4
+ //Do not make this file exportable, it is only for internal use.
5
+ export const arr = Symbol.for('MHtiI353KU+aKBDlz/jR+A');
@@ -0,0 +1,5 @@
1
+ //using Symbol.for, which is easily hackaable, because if two different entry points
2
+ //come from different versions of mount-observer, things could get out of sync.
3
+ //Not an issue if this was built into the browser, but it is an issue for a custom a library.
4
+ //Do not make this file exportable, it is only for internal use.
5
+ export const arr = Symbol.for('MHtiI353KU+aKBDlz/jR+A');
@@ -216,6 +216,8 @@ export interface BindishOptions{
216
216
  * to indicate that the initial
217
217
  */
218
218
  csr?: boolean,
219
+ ctr?: {new() : Ishcycle},
220
+ initPropVals?: any,
219
221
  }
220
222
 
221
223
  export interface Ishcycle{
@@ -190,6 +190,7 @@ export interface IshConfig<TProps = any, TActions = TProps, ETProps = TProps>{
190
190
  isSleepless?: boolean;
191
191
  xform?: XForm<TProps, TActions>;
192
192
  inScopeXForms?: {[key: CSSQuery]: XForm<TProps, TActions>};
193
+ ishListCountProp?: keyof TProps & string;
193
194
  }
194
195
  export interface OConfig<TProps = any, TActions = TProps, ETProps = TProps> extends IshConfig<TProps, TActions, ETProps>{
195
196
  mainTemplate?: string | HTMLTemplateElement;