@domql/element 2.5.12 → 2.5.13

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/create.js CHANGED
@@ -172,6 +172,7 @@ const cacheOptions = (element, options) => {
172
172
 
173
173
  const createKey = (element, parent, key) => {
174
174
  return (
175
+ exec(key, element) ||
175
176
  key ||
176
177
  element.key ||
177
178
  generateKey()
@@ -133,7 +133,7 @@ const cacheOptions = (element, options) => {
133
133
  }
134
134
  };
135
135
  const createKey = (element, parent, key) => {
136
- return (key || element.key || (0, import_utils.generateKey)()).toString();
136
+ return ((0, import_utils.exec)(key, element) || key || element.key || (0, import_utils.generateKey)()).toString();
137
137
  };
138
138
  const addRef = (element, parent) => {
139
139
  if (element.__ref)
package/dist/cjs/node.js CHANGED
@@ -73,7 +73,11 @@ const createNode = (element, options) => {
73
73
  if (isElement) {
74
74
  const { hasDefine, hasContextDefine } = isElement;
75
75
  if (element[param] && !hasDefine && !hasContextDefine) {
76
- (0, import_create.default)((0, import_utils.exec)(prop, element), element, param, options);
76
+ const createAsync = () => (0, import_create.default)((0, import_utils.exec)(prop, element), element, param, options);
77
+ if (element.props && element.props.lazyLoad || options.lazyLoad) {
78
+ window.requestAnimationFrame(() => createAsync());
79
+ } else
80
+ createAsync();
77
81
  }
78
82
  }
79
83
  }
package/node.js CHANGED
@@ -69,7 +69,11 @@ export const createNode = (element, options) => {
69
69
  if (isElement) {
70
70
  const { hasDefine, hasContextDefine } = isElement
71
71
  if (element[param] && !hasDefine && !hasContextDefine) {
72
- create(exec(prop, element), element, param, options)
72
+ const createAsync = () => create(exec(prop, element), element, param, options)
73
+
74
+ if ((element.props && element.props.lazyLoad) || options.lazyLoad) {
75
+ window.requestAnimationFrame(() => createAsync())
76
+ } else createAsync()
73
77
  }
74
78
  }
75
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.12",
3
+ "version": "2.5.13",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -31,7 +31,7 @@
31
31
  "@domql/state": "latest",
32
32
  "@domql/utils": "latest"
33
33
  },
34
- "gitHead": "f17796f71477b72a3b8703b2ac65b5e9ff7e93e2",
34
+ "gitHead": "3bbff7f4e2ced6f104572489a2779a5cf0dbb450",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var import__ = require("../");
3
- const dom = (0, import__.create)({});
4
- test("should create EMPTY element", () => {
5
- expect(dom).toHaveProperty("key");
6
- expect(dom).toHaveProperty("state");
7
- expect(dom).toHaveProperty("parent");
8
- expect(dom).toHaveProperty("node");
9
- expect(dom).toHaveProperty("set");
10
- expect(dom).toHaveProperty("update");
11
- expect(dom).toHaveProperty("__ref");
12
- });
13
- test("should create valid DOM node", () => {
14
- expect(dom.node).toBeInstanceOf(window.HTMLDivElement);
15
- });
16
- test("must be able to create valid PATH", () => {
17
- expect(dom.__ref.__path).toStrictEqual([dom.key]);
18
- });
19
- test("if it HAS a NODE, don't recreate", () => {
20
- const node = document.createElement("div");
21
- const dom2 = (0, import__.create)({ node });
22
- expect(dom2.node.parentElement).toBe(document.body);
23
- });
24
- test("create with number", () => {
25
- const numb = (0, import__.create)(0);
26
- expect(numb.text).toBe(0);
27
- expect(numb.tag).toBe("string");
28
- expect(numb.node.nodeType).toBe(3);
29
- });
30
- test("create with string", () => {
31
- const str = (0, import__.create)("hello");
32
- expect(str.text).toBe("hello");
33
- expect(str.tag).toBe("string");
34
- expect(str.node.nodeType).toBe(3);
35
- });
36
- test("creating conditions", () => {
37
- const element = (0, import__.create)({
38
- data: { visible: true },
39
- if: (element2) => element2.data.visible
40
- });
41
- expect(element.tag).toBe("div");
42
- });
43
- test("creating nesting", () => {
44
- const element = (0, import__.create)({
45
- header: {
46
- h1: {}
47
- }
48
- });
49
- expect(element.header.tag).toBe("header");
50
- expect(element.header.h1.tag).toBe("h1");
51
- });
@@ -1,28 +0,0 @@
1
- const { isMethod, METHODS } = require("../dist/cjs");
2
- describe("isMethod", () => {
3
- test("returns true if parameter is a method", () => {
4
- const validMethod = "set";
5
- const result = isMethod(validMethod);
6
- expect(result).toBe(true);
7
- });
8
- test("returns false if parameter is not a method", () => {
9
- const invalidMethod = "invalidMethod";
10
- const result = isMethod(invalidMethod);
11
- expect(result).toBe(false);
12
- });
13
- test("returns false if parameter is not a string", () => {
14
- const invalidParam = 123;
15
- const result = isMethod(invalidParam);
16
- expect(result).toBe(false);
17
- });
18
- test("returns true if parameter is a valid method in the METHODS array", () => {
19
- const validMethod = METHODS[0];
20
- const result = isMethod(validMethod);
21
- expect(result).toBe(true);
22
- });
23
- test("returns false if parameter is not a valid method in the METHODS array", () => {
24
- const invalidMethod = "invalidMethod";
25
- const result = isMethod(invalidMethod);
26
- expect(result).toBe(false);
27
- });
28
- });
@@ -1,9 +0,0 @@
1
- "use strict";
2
- var import__ = require("../");
3
- const element = (0, import__.create)({});
4
- test("should SET element", () => {
5
- element.set({ text: "test" });
6
- expect(element.content.text).toBe("test");
7
- element.set({ text: "test2" });
8
- expect(element.content.text).toBe("test2");
9
- });
@@ -1,8 +0,0 @@
1
- "use strict";
2
- var import__ = require("../");
3
- const element = (0, import__.create)({});
4
- test("should UPDATE element", () => {
5
- expect(element.text).toBeUndefined();
6
- element.update("test");
7
- expect(element.text).toBe("test");
8
- });
@@ -1,61 +0,0 @@
1
- 'use strict'
2
-
3
- import { create } from '../'
4
-
5
- const dom = create({})
6
-
7
- test('should create EMPTY element', () => {
8
- expect(dom).toHaveProperty('key')
9
- expect(dom).toHaveProperty('state')
10
- expect(dom).toHaveProperty('parent')
11
- expect(dom).toHaveProperty('node')
12
- expect(dom).toHaveProperty('set')
13
- expect(dom).toHaveProperty('update')
14
- expect(dom).toHaveProperty('__ref')
15
- })
16
-
17
- test('should create valid DOM node', () => {
18
- expect(dom.node).toBeInstanceOf(window.HTMLDivElement)
19
- })
20
-
21
- test('must be able to create valid PATH', () => {
22
- expect(dom.__ref.__path).toStrictEqual([dom.key])
23
- })
24
-
25
- test('if it HAS a NODE, don\'t recreate', () => {
26
- const node = document.createElement('div')
27
- const dom2 = create({ node })
28
- expect(dom2.node.parentElement).toBe(document.body)
29
- })
30
-
31
- test('create with number', () => {
32
- const numb = create(0)
33
- expect(numb.text).toBe(0)
34
- expect(numb.tag).toBe('string')
35
- expect(numb.node.nodeType).toBe(3) // #text
36
- })
37
-
38
- test('create with string', () => {
39
- const str = create('hello')
40
- expect(str.text).toBe('hello')
41
- expect(str.tag).toBe('string')
42
- expect(str.node.nodeType).toBe(3) // #text
43
- })
44
-
45
- test('creating conditions', () => {
46
- const element = create({
47
- data: { visible: true },
48
- if: element => element.data.visible
49
- })
50
- expect(element.tag).toBe('div')
51
- })
52
-
53
- test('creating nesting', () => {
54
- const element = create({
55
- header: {
56
- h1: {}
57
- }
58
- })
59
- expect(element.header.tag).toBe('header')
60
- expect(element.header.h1.tag).toBe('h1')
61
- })
@@ -1,38 +0,0 @@
1
- const { isMethod, METHODS } = require('../dist/cjs')
2
-
3
- describe('isMethod', () => {
4
- test('returns true if parameter is a method', () => {
5
- const validMethod = 'set'
6
- const result = isMethod(validMethod)
7
-
8
- expect(result).toBe(true)
9
- })
10
-
11
- test('returns false if parameter is not a method', () => {
12
- const invalidMethod = 'invalidMethod'
13
- const result = isMethod(invalidMethod)
14
-
15
- expect(result).toBe(false)
16
- })
17
-
18
- test('returns false if parameter is not a string', () => {
19
- const invalidParam = 123
20
- const result = isMethod(invalidParam)
21
-
22
- expect(result).toBe(false)
23
- })
24
-
25
- test('returns true if parameter is a valid method in the METHODS array', () => {
26
- const validMethod = METHODS[0]
27
- const result = isMethod(validMethod)
28
-
29
- expect(result).toBe(true)
30
- })
31
-
32
- test('returns false if parameter is not a valid method in the METHODS array', () => {
33
- const invalidMethod = 'invalidMethod'
34
- const result = isMethod(invalidMethod)
35
-
36
- expect(result).toBe(false)
37
- })
38
- })
package/test/set.test.js DELETED
@@ -1,13 +0,0 @@
1
- 'use strict'
2
-
3
- import { create } from '../'
4
-
5
- const element = create({})
6
-
7
- test('should SET element', () => {
8
- element.set({ text: 'test' })
9
- expect(element.content.text).toBe('test')
10
-
11
- element.set({ text: 'test2' })
12
- expect(element.content.text).toBe('test2')
13
- })
@@ -1,13 +0,0 @@
1
- 'use strict'
2
-
3
- import { create } from '../'
4
-
5
- const element = create({})
6
-
7
- test('should UPDATE element', () => {
8
- expect(element.text).toBeUndefined()
9
-
10
- element.update('test')
11
-
12
- expect(element.text).toBe('test')
13
- })