|
40 | 40 | } |
41 | 41 | } |
42 | 42 |
|
| 43 | + // import { this.$app.$syntax } from "./enums"; |
| 44 | + |
43 | 45 | function createKey() { |
44 | 46 | return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { |
45 | 47 | var r = (Math.random() * 16) | 0, |
|
60 | 62 | function splitKeyValuePairs(string) { |
61 | 63 | return string |
62 | 64 | .trim() |
63 | | - .split(relationalStringEnum.KEY_VALUE) |
| 65 | + .split(this.$app.$syntax.KEY_VALUE) |
64 | 66 | .map(item => item.trim()); |
65 | 67 | } |
66 | 68 | function splitMultipleValues(string) { |
67 | 69 | return string |
68 | 70 | .trim() |
69 | | - .split(relationalStringEnum.MULTIPLE_VALUES) |
| 71 | + .split(this.$app.$syntax.MULTIPLE_VALUES) |
70 | 72 | .map(item => item.trim()); |
71 | 73 | } |
72 | 74 | function splitPropsPassedIn(string) { |
|
78 | 80 | /* END.DEV */ |
79 | 81 | return string |
80 | 82 | .trim() |
81 | | - .split(relationalStringEnum.INHERITS_FROM) |
| 83 | + .split(this.$app.$syntax.INHERITS_FROM) |
82 | 84 | .map(item => item.trim()); |
83 | 85 | } |
84 | 86 | function splitMethodCalls(string) { |
|
90 | 92 | /* END.DEV */ |
91 | 93 | return string |
92 | 94 | .trim() |
93 | | - .split(relationalStringEnum.METHOD_CALL) |
| 95 | + .split(this.$app.$syntax.METHOD_CALL) |
94 | 96 | .map(item => item.trim()); |
95 | 97 | } |
96 | 98 | function splitFromComponent(string) { |
|
102 | 104 | /* END.DEV */ |
103 | 105 | return string |
104 | 106 | .trim() |
105 | | - .split(relationalStringEnum.FROM_COMPONENT) |
| 107 | + .split(this.$app.$syntax.FROM_COMPONENT) |
106 | 108 | .map(item => item.trim()); |
107 | 109 | } |
108 | 110 | function splitList(string) { |
109 | 111 | return string |
110 | 112 | .trim() |
111 | | - .split(relationalStringEnum.LIST) |
| 113 | + .split(this.$app.$syntax.LIST) |
112 | 114 | .map(item => item.trim()); |
113 | 115 | } |
114 | 116 |
|
115 | 117 | function createStateObjects() { |
| 118 | + const self = this; |
| 119 | + |
116 | 120 | const nodes = scopeElements.call( |
117 | 121 | this, |
118 | | - `[data-${this.$app.$datasets.bind}^="state:"]` |
| 122 | + `[data-${this.$app.$datasets.bind}^="state${this.$app.$syntax.KEY_VALUE}"]` |
119 | 123 | ); |
120 | 124 | if (nodes.length > 0) { |
121 | 125 | const $s = {}; |
|
124 | 128 | /* START.DEV */ |
125 | 129 | try { |
126 | 130 | /* END.DEV */ |
127 | | - var states = splitMultipleValues( |
| 131 | + var states = splitMultipleValues.call(self, |
128 | 132 | el.getAttribute(`data-${this.$app.$datasets.bind}`) |
129 | 133 | ); |
130 | 134 | /* START.DEV */ |
|
138 | 142 | /* START.DEV */ |
139 | 143 | try { |
140 | 144 | /* END.DEV */ |
141 | | - var parts = splitKeyValuePairs(state); |
| 145 | + var parts = splitKeyValuePairs.call(self, state); |
142 | 146 | /* START.DEV */ |
143 | 147 | } catch (err) { |
144 | 148 | console.error(`🤓 -- "There's a problem creating the state. |
|
149 | 153 | /* START.DEV */ |
150 | 154 | try { |
151 | 155 | /* END.DEV */ |
152 | | - var stateKey = splitFromComponent(parts[1])[1]; |
| 156 | + var stateKey = splitFromComponent.call(self, parts[1])[1]; |
153 | 157 | /* START.DEV */ |
154 | 158 | } catch (err) { |
155 | 159 | console.error(`🤓 -- "There's a problem creating the state. |
|
190 | 194 | } |
191 | 195 |
|
192 | 196 | function bindListeners() { |
| 197 | + const self = this; |
193 | 198 | this.$b = []; |
194 | 199 | let arr = this.$root.getAttribute(`data-${this.$app.$datasets.action}`) |
195 | 200 | ? [this.$root] |
196 | 201 | : []; |
197 | 202 | arr |
198 | 203 | .concat(scopeElements.call(this, `[data-${this.$app.$datasets.action}]`)) |
199 | 204 | .forEach(el => { |
200 | | - const actions = splitMultipleValues( |
| 205 | + const actions = splitMultipleValues.call(self, |
201 | 206 | el.getAttribute(`data-${this.$app.$datasets.action}`) |
202 | 207 | ); |
203 | 208 | const binding = { |
204 | 209 | el: el, |
205 | 210 | actions: [] |
206 | 211 | }; |
207 | 212 | actions.forEach(action => { |
208 | | - const parts = splitMethodCalls(action); |
| 213 | + const parts = splitMethodCalls.call(self, action); |
209 | 214 | const event = parts[0]; |
210 | | - const cbFunc = splitFromComponent(parts[1]); |
| 215 | + const cbFunc = splitFromComponent.call(self, parts[1]); |
211 | 216 | if (cbFunc[0] === this.$name) { |
212 | 217 | let options = {}; |
213 | 218 | if (cbFunc[2]) { |
214 | | - const arr = splitList(cbFunc[2]); |
| 219 | + const arr = splitList.call(self, cbFunc[2]); |
215 | 220 | for (let key in eventOptions) { |
216 | 221 | options[eventOptions[key]] = arr.includes(eventOptions[key]); |
217 | 222 | } |
|
291 | 296 | } |
292 | 297 |
|
293 | 298 | function createPropObjects() { |
| 299 | + const self = this; |
294 | 300 | const attr = this.$root.getAttribute(`data-${this.$app.$datasets.props}`); |
295 | 301 | if (attr) { |
296 | 302 | const $p = {}; |
297 | | - const props = splitMultipleValues(attr); |
| 303 | + const props = splitMultipleValues.call(self, attr); |
298 | 304 | props.forEach(prop => { |
299 | | - const propStringValues = splitPropsPassedIn(prop); |
300 | | - const parentComponentValues = splitKeyValuePairs(propStringValues[1]); |
| 305 | + const propStringValues = splitPropsPassedIn.call(self, prop); |
| 306 | + const parentComponentValues = splitKeyValuePairs.call(self, propStringValues[1]); |
301 | 307 | const propName = propStringValues[0]; |
302 | 308 | const parentComponent = this.$app.registeredComponents[ |
303 | 309 | parentComponentValues[0] |
|
308 | 314 | const els = [ |
309 | 315 | ...scopeElements.call( |
310 | 316 | this, |
311 | | - `[${this.$app.$datasets.bind}^="props:${propName}"]` |
| 317 | + `[${this.$app.$datasets.bind}^="props${this.$app.$syntax.KEY_VALUE}${propName}"]` |
312 | 318 | ) |
313 | 319 | ]; |
314 | 320 | this.props[propName] = parentComponent.state[parentComponentKey]; |
|
325 | 331 | } |
326 | 332 |
|
327 | 333 | function createRefs() { |
| 334 | + const self = this; |
| 335 | + |
328 | 336 | scopeElements |
329 | | - .call(this, `[data-${this.$app.$datasets.ref}*='${this.$name}.']`) |
| 337 | + .call( |
| 338 | + this, |
| 339 | + `[data-${this.$app.$datasets.ref}*='${this.$name}${this.$app.$syntax.FROM_COMPONENT}']` |
| 340 | + ) |
330 | 341 | .forEach(element => { |
331 | 342 | this[ |
332 | | - splitFromComponent( |
| 343 | + splitFromComponent.call(self, |
333 | 344 | element.getAttribute(`data-${this.$app.$datasets.ref}`) |
334 | 345 | )[1] |
335 | 346 | ] = element; |
|
338 | 349 |
|
339 | 350 | function createRefArrays() { |
340 | 351 | let prevKey = null; |
| 352 | + const self = this; |
| 353 | + |
341 | 354 | scopeElements |
342 | | - .call(this, `[data-${this.$app.$datasets.ref_array}*='${this.$name}.']`) |
| 355 | + .call( |
| 356 | + this, |
| 357 | + `[data-${this.$app.$datasets.ref_array}*='${this.$name}${this.$app.$syntax.FROM_COMPONENT}']` |
| 358 | + ) |
343 | 359 | .forEach(element => { |
344 | | - const key = splitFromComponent( |
| 360 | + const key = splitFromComponent.call(self, |
345 | 361 | element.getAttribute(`data-${this.$app.$datasets.ref_array}`) |
346 | 362 | )[1]; |
347 | 363 | if (key === prevKey) { |
@@ -474,6 +490,26 @@ See ya soon!"`); |
474 | 490 | return dataSet; |
475 | 491 | })(); |
476 | 492 |
|
| 493 | + // custom syntax to avoid collisions |
| 494 | + this.$syntax = (() => { |
| 495 | + const syntax = relationalStringEnum; |
| 496 | + if (config.customSyntax) { |
| 497 | + for (let key in config.customSyntax) { |
| 498 | + syntax[key] = config.customSyntax[key]; |
| 499 | + } |
| 500 | + } |
| 501 | + /* START.DEV */ |
| 502 | + console.log( |
| 503 | + `🤓 -- "Dom here. Your custom syntax is in this object: |
| 504 | + `, |
| 505 | + syntax, |
| 506 | + ` |
| 507 | + Sweet, dude!"` |
| 508 | + ); |
| 509 | + /* END.DEV */ |
| 510 | + return syntax; |
| 511 | + })(); |
| 512 | + |
477 | 513 | // methods to expose |
478 | 514 | // create component |
479 | 515 | this._cc = (el, cb) => { |
|
0 commit comments