Skip to content

Commit 4c7fe97

Browse files
committed
remove set:: does not work as intended (events not customizable)
1 parent 227caf0 commit 4c7fe97

File tree

4 files changed

+60
-70
lines changed

4 files changed

+60
-70
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ The Bindings are heavily inspired by polymer
3939
use [[expression]] for one way bindings
4040

4141
use {{this.property::change;paste}} for two way bindings which listens to events 'change 'and 'paste'
42-
use "set:name="{{this.property::change;paste}}"" as setter only property Binding, so you can define different code for get & set.
4342

4443
css:cssPropertyName="[[expression]]" to bind to a css property
4544

package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
{
2-
"description": "Base Custom Webcomponent",
3-
"name": "@node-projects/base-custom-webcomponent",
4-
"version": "0.4.0",
5-
"type": "module",
6-
"main": "./dist/index.js",
7-
"author": "",
8-
"license": "BSD-3-Clause",
9-
"scripts": {
10-
"tsc": "tsc"
11-
},
12-
"devDependencies": {
13-
"typescript": "^4.5.2"
14-
},
15-
"repository": {
16-
"type": "git",
17-
"url": "git+https://github.com/node-projects/base-custom-webcomponent.git"
18-
},
19-
"bugs": {
20-
"url": "https://github.com/node-projects/base-custom-webcomponent/issues"
21-
},
22-
"homepage": "https://github.com/node-projects/base-custom-webcomponent#readme"
23-
}
1+
{
2+
"description": "Base Custom Webcomponent",
3+
"name": "@node-projects/base-custom-webcomponent",
4+
"version": "0.4.1",
5+
"type": "module",
6+
"main": "./dist/index.js",
7+
"author": "",
8+
"license": "BSD-3-Clause",
9+
"scripts": {
10+
"tsc": "tsc"
11+
},
12+
"devDependencies": {
13+
"typescript": "^4.5.4"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/node-projects/base-custom-webcomponent.git"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/node-projects/base-custom-webcomponent/issues"
21+
},
22+
"homepage": "https://github.com/node-projects/base-custom-webcomponent#readme"
23+
}

src/BaseCustomWebComponent.ts

+28-37
Original file line numberDiff line numberDiff line change
@@ -151,37 +151,37 @@ export class BaseCustomWebComponentNoAttachedTemplate extends HTMLElement {
151151
if (!node)
152152
node = this.shadowRoot.childNodes.length > 0 ? this.shadowRoot : this._rootDocumentFragment;
153153
if (node instanceof Element) { //node.nodeType === 1
154-
let attributes = Array.from(node.attributes);
154+
const attributes = Array.from(node.attributes);
155155
for (let a of attributes) {
156156
if (a.name.startsWith('css:') && a.value.startsWith('[[') && a.value.endsWith(']]')) {
157-
let value = a.value.substring(2, a.value.length - 2).replaceAll('&', '&');
158-
let camelCased = a.name.substring(4, a.name.length).replace(/-([a-z])/g, (g) => g[1].toUpperCase());
157+
const value = a.value.substring(2, a.value.length - 2).replaceAll('&', '&');
158+
const camelCased = a.name.substring(4, a.name.length).replace(/-([a-z])/g, (g) => g[1].toUpperCase());
159159
this._bindings.push(() => this._bindingSetElementCssValue(<HTMLElement | SVGElement>node, camelCased, value, repeatBindingItems, host, context));
160160
this._bindings[this._bindings.length - 1](true);
161161
} else if (a.name.startsWith('class:') && a.value.startsWith('[[') && a.value.endsWith(']]')) {
162-
let value = a.value.substring(2, a.value.length - 2).replaceAll('&amp;', '&');
163-
let camelCased = a.name.substring(6, a.name.length).replace(/-([a-z])/g, (g) => g[1].toUpperCase());
162+
const value = a.value.substring(2, a.value.length - 2).replaceAll('&amp;', '&');
163+
const camelCased = a.name.substring(6, a.name.length).replace(/-([a-z])/g, (g) => g[1].toUpperCase());
164164
this._bindings.push(() => this._bindingSetElementClass(<HTMLElement | SVGElement>node, camelCased, value, repeatBindingItems, host, context));
165165
this._bindings[this._bindings.length - 1](true);
166166
} else if (a.name == 'repeat-changed-item-callback') {
167167
//do nothing
168168
} else if (a.name.startsWith('repeat:') && a.value.startsWith('[[') && a.value.endsWith(']]')) {
169-
let value = a.value.substring(2, a.value.length - 2).replaceAll('&amp;', '&');
170-
let bindingItemVariableName = a.name.substring(7, a.name.length).replace(/-([a-z])/g, (g) => g[1].toUpperCase());
171-
let elementsCache: Node[] = [];
169+
const value = a.value.substring(2, a.value.length - 2).replaceAll('&amp;', '&');
170+
const bindingItemVariableName = a.name.substring(7, a.name.length).replace(/-([a-z])/g, (g) => g[1].toUpperCase());
171+
const elementsCache: Node[] = [];
172172
let bindingIndexname = 'index';
173173
let changeItemCallback = null;
174-
let indexNameAttribute = attributes.find(x => x.name == 'repeat-index');
174+
const indexNameAttribute = attributes.find(x => x.name == 'repeat-index');
175175
if (indexNameAttribute)
176176
bindingIndexname = indexNameAttribute.value;
177-
let changeItemCallbackAttribute = attributes.find(x => x.name == 'repeat-changed-item-callback');
177+
const changeItemCallbackAttribute = attributes.find(x => x.name == 'repeat-changed-item-callback');
178178
if (changeItemCallbackAttribute)
179179
changeItemCallback = changeItemCallbackAttribute.value;
180180
this._bindings.push(() => this._bindingRepeat(<HTMLTemplateElement>node, bindingItemVariableName, bindingIndexname, value, changeItemCallback, repeatBindingItems, elementsCache, host, context));
181181
this._bindings[this._bindings.length - 1](true);
182182
} else if (a.name.startsWith('@') && a.value.startsWith('[[') && a.value.endsWith(']]')) { //todo remove events on repeat refresh
183-
let value = a.value.substring(2, a.value.length - 2).replaceAll('&amp;', '&');
184-
let camelCased = a.name.substring(1, a.name.length).replace(/-([a-z])/g, (g) => g[1].toUpperCase());
183+
const value = a.value.substring(2, a.value.length - 2).replaceAll('&amp;', '&');
184+
const camelCased = a.name.substring(1, a.name.length).replace(/-([a-z])/g, (g) => g[1].toUpperCase());
185185
if (a.name == "@touch:contextmenu")
186186
addTouchFriendlyContextMenu(node, (e) => this._bindingRunEval(value, repeatBindingItems, e, host, context));
187187
else {
@@ -193,7 +193,7 @@ export class BaseCustomWebComponentNoAttachedTemplate extends HTMLElement {
193193
}
194194
} else if (a.value.startsWith('[[') && a.value.endsWith(']]')) {
195195
let value = a.value.substring(2, a.value.length - 2).replaceAll('&amp;', '&');
196-
let camelCased = a.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
196+
const camelCased = a.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
197197
let noNull = false;
198198
if (value.startsWith('?')) {
199199
value = value.substring(1);
@@ -207,50 +207,41 @@ export class BaseCustomWebComponentNoAttachedTemplate extends HTMLElement {
207207
let event = 'input';
208208
if (attributeValues.length > 1 && attributeValues[1])
209209
event = attributeValues[1];
210-
let camelCased = a.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
211-
if (camelCased.startsWith('set:')) {
212-
const pName = camelCased.substring(4);
213-
event.split(';').forEach(x => node.addEventListener(x, (e) => {
214-
let ctx = { value: node[pName] };
215-
ctx[pName] = node[pName]; //value is in value or property-name
216-
this._bindingRunEval(value, repeatBindingItems, e, host, { value: node[pName] })
217-
}));
218-
} else {
219-
let noNull = false;
220-
if (value.startsWith('?')) {
221-
value = value.substring(1);
222-
noNull = true;
223-
}
224-
this._bindings.push((firstRun?: boolean) => this._bindingSetNodeValue(firstRun, node, a, camelCased, value, repeatBindingItems, removeAttributes, host, context, noNull));
225-
this._bindings[this._bindings.length - 1](true);
226-
if (event) {
227-
event.split(';').forEach(x => node.addEventListener(x, (e) => this._bindingsSetValue(this, value, (<HTMLInputElement>node)[camelCased])));
228-
}
210+
const camelCased = a.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
211+
let noNull = false;
212+
if (value.startsWith('?')) {
213+
value = value.substring(1);
214+
noNull = true;
215+
}
216+
this._bindings.push((firstRun?: boolean) => this._bindingSetNodeValue(firstRun, node, a, camelCased, value, repeatBindingItems, removeAttributes, host, context, noNull));
217+
this._bindings[this._bindings.length - 1](true);
218+
if (event) {
219+
event.split(';').forEach(x => node.addEventListener(x, (e) => this._bindingsSetValue(this, value, (<HTMLInputElement>node)[camelCased])));
229220
}
230221
}
231222
}
232223
} else if (node.nodeType === 3) {
233224
if (node.nodeValue.indexOf('[[') >= 0) {
234225
const text = node.nodeValue;
235-
let matches = text.matchAll((<RegExp>(<any>this.constructor)._bindingRegex));
226+
const matches = text.matchAll((<RegExp>(<any>this.constructor)._bindingRegex));
236227
let lastindex = 0;
237228
let fragment: DocumentFragment;
238229
for (let m of matches) {
239230
if (m.index == 0 && m[0].length == text.length && node.parentNode.childNodes.length == 1) {
240-
let value = m[0].substr(2, m[0].length - 4);
241-
let parent = node.parentNode;
231+
const value = m[0].substr(2, m[0].length - 4);
232+
const parent = node.parentNode;
242233
node.parentNode.removeChild(node);
243234
this._bindings.push((firstRun?: boolean) => this._bindingSetNodeValue(firstRun, parent, null, 'innerHTML', value, repeatBindingItems, removeAttributes, host, context, false));
244235
this._bindings[this._bindings.length - 1](true);
245236
} else {
246237
if (!fragment)
247238
fragment = document.createDocumentFragment();
248239
if (m.index - lastindex > 0) {
249-
let tn = document.createTextNode(text.substr(lastindex, m.index - lastindex));
240+
const tn = document.createTextNode(text.substr(lastindex, m.index - lastindex));
250241
fragment.appendChild(tn);
251242
}
252243
const newNode = document.createElement('span');
253-
let value = m[0].substr(2, m[0].length - 4);
244+
const value = m[0].substr(2, m[0].length - 4);
254245
this._bindings.push((firstRun?: boolean) => this._bindingSetNodeValue(firstRun, newNode, null, 'innerHTML', value, repeatBindingItems, removeAttributes, host, context, false));
255246
this._bindings[this._bindings.length - 1](true);
256247
fragment.appendChild(newNode);

0 commit comments

Comments
 (0)