mount-observer 0.0.63 → 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,7 +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
+ import { arr } from './refid/secretKeys.js';
6
6
  export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
7
7
  export class Newish {
8
8
  queue = [];
@@ -26,19 +26,29 @@ export class Newish {
26
26
  if (enhancedElement[attached] === true)
27
27
  return;
28
28
  enhancedElement[attached] = true;
29
- const ctr = await getIsh(enhancedElement.isConnected ? enhancedElement : target, itemscope);
30
- const initPropVals = enhancedElement['ish'];
31
- if (enhancedElement instanceof HTMLElement) {
32
- if (enhancedElement.dataset.ish) {
33
- const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
34
- this.queue.push(parsedHostProps);
35
- }
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);
36
51
  }
37
- const resolvedConstructor = ctr.constructor.name === 'AsyncFunction' ? await ctr() : ctr;
38
- const isInstance = initPropVals instanceof resolvedConstructor;
39
- const ce = isInstance ? initPropVals : new resolvedConstructor();
40
- if (initPropVals !== undefined && !isInstance)
41
- this.queue.push(initPropVals);
42
52
  if ('<mount>' in ce && typeof ce['<mount>'] === 'function') {
43
53
  await ce['<mount>'](ce, enhancedElement, this.#options);
44
54
  }
@@ -99,7 +109,11 @@ export class Newish {
99
109
  //TODO: Provide support for a virtual slice of a very large list
100
110
  //TODO: Maybe should check if iterable rather than an array?
101
111
  if (Array.isArray(fi)) {
102
- ce[sym] = 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;
103
117
  actions.add('ishListAssigned');
104
118
  }
105
119
  else {
package/Newish.ts CHANGED
@@ -1,15 +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 {sym} from './refid/regIsh.js';
7
+ import {arr} from './refid/secretKeys.js';
8
8
  export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
9
9
  export class Newish implements EventListenerObject {
10
10
  queue: Array<any> = [];
11
11
  isResolved = false;
12
- #ce: HTMLElement | undefined;
12
+ #ce: Ishcycle | undefined;
13
13
  #ref: WeakRef<Element>;
14
14
 
15
15
  //#assigner: undefined | Assigner = undefined;
@@ -35,21 +35,31 @@ export class Newish implements EventListenerObject {
35
35
  ){
36
36
  if((<any>enhancedElement)[attached] === true) return;
37
37
  (<any>enhancedElement)[attached] = true;
38
- const ctr = await getIsh(enhancedElement.isConnected ? enhancedElement :target, itemscope)! as any;
39
-
40
- const initPropVals = (<any>enhancedElement)['ish'];
41
- if(enhancedElement instanceof HTMLElement){
42
- if(enhancedElement.dataset.ish){
43
- const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
44
- this.queue.push(parsedHostProps);
45
- }
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);
46
60
  }
47
-
48
-
49
- const resolvedConstructor = ctr.constructor.name === 'AsyncFunction' ? await ctr() : ctr;
50
- const isInstance = initPropVals instanceof resolvedConstructor
51
- const ce = isInstance ? initPropVals : new resolvedConstructor();
52
- if(initPropVals !== undefined && !isInstance) this.queue.push(initPropVals);
61
+
62
+
53
63
 
54
64
  if('<mount>' in ce && typeof ce['<mount>'] === 'function'){
55
65
  await ce['<mount>'](ce, enhancedElement, this.#options)
@@ -115,7 +125,11 @@ export class Newish implements EventListenerObject {
115
125
  //TODO: Provide support for a virtual slice of a very large list
116
126
  //TODO: Maybe should check if iterable rather than an array?
117
127
  if(Array.isArray(fi)){
118
- (<any>ce)[sym] = 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;
119
133
  actions.add('ishListAssigned');
120
134
  }else{
121
135
  const {assigner} = this.#options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.63",
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) {
@@ -12,7 +13,7 @@ export function regIsh(scope, name, ctr) {
12
13
  map.set(name, ctr);
13
14
  ctr.prototype[Symbol.iterator] = function () {
14
15
  var index = -1;
15
- var data = this[sym];
16
+ var data = this[arr];
16
17
  return {
17
18
  next: function () {
18
19
  return {
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>;
@@ -14,7 +15,7 @@ export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr
14
15
  map.set(name, ctr);
15
16
  ctr.prototype[Symbol.iterator] = function() {
16
17
  var index = -1;
17
- var data = this[sym];
18
+ var data = this[arr];
18
19
 
19
20
  return {
20
21
  next: function() {
@@ -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;