@linear_non/stellar-kit 2.1.14 → 2.1.16

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.
@@ -1,11 +1,20 @@
1
+ // Manager.js
1
2
  import { qsa } from "../utils"
2
3
 
3
4
  export default class Manager {
4
5
  constructor({ data = {} } = {}) {
5
- this.components = []
6
+ this.components = [] // { name, component }
6
7
  this.data = data
7
8
  }
8
9
 
10
+ getComponents(name) {
11
+ return this.components.filter(c => c.name === name).map(c => c.component)
12
+ }
13
+
14
+ getComponent(name, index = 0) {
15
+ return this.getComponents(name)[index] || null
16
+ }
17
+
9
18
  addComponent(def, renderer = null) {
10
19
  if (!def || !def.instance || !def.name) return
11
20
 
@@ -14,10 +23,8 @@ export default class Manager {
14
23
  // resolve selector from name
15
24
  let selector
16
25
  if (name.startsWith(".") || name.startsWith("[")) {
17
- // "Class: .c-hero" or "Attribute: [data-hero]"
18
26
  selector = name
19
27
  } else {
20
- // "Transform: hero" -> "[data-hero]"
21
28
  selector = `[data-${name}]`
22
29
  }
23
30
 
@@ -27,7 +34,7 @@ export default class Manager {
27
34
  const mergedData = data ? { ...this.data, ...data } : this.data
28
35
 
29
36
  els.forEach((el, index) => {
30
- const c = new instance({
37
+ const component = new instance({
31
38
  el,
32
39
  index,
33
40
  name,
@@ -35,12 +42,17 @@ export default class Manager {
35
42
  data: mergedData,
36
43
  })
37
44
 
38
- this.components.push(c)
45
+ this.components.push({
46
+ name,
47
+ component,
48
+ })
39
49
  })
40
50
  }
41
51
 
52
+ // INTERNAL CALLER
42
53
  _call(method, ...args) {
43
- this.components.forEach(c => {
54
+ this.components.forEach(entry => {
55
+ const c = entry.component
44
56
  const fn = c[method]
45
57
  if (typeof fn === "function") fn.apply(c, args)
46
58
  })
@@ -1,4 +1,4 @@
1
- //MasterLoader.js
1
+ // MasterLoader.js
2
2
  import { emitter, EVENTS } from "../events"
3
3
 
4
4
  export default class MasterLoader {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linear_non/stellar-kit",
3
- "version": "2.1.14",
3
+ "version": "2.1.16",
4
4
  "description": "Stellar frontend core for Non-Linear Studio projects.",
5
5
  "main": "index.js",
6
6
  "exports": {