-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Short syntax for simple modes #444
Comments
Before: block('button').match(function() { return this._attachButton; })(
tag()('span'),
match(function() { return !!this._disabled; })
.mix()({ mods: { disabled: 'yes' } }),
def()(function() {
return applyNext({
_name: this.ctx.name || 'attachment',
_id: this.ctx.id || this.generateId(),
_textId: 'text' + this._id,
_tabindex: this.ctx.tabindex
});
}),
attrs()({}), // принудительно сбрасываем все атрибуты
content()(function() {
var p = applyNext(),
a = {
block: 'attach',
elem: 'control',
attrs: this.ctx.controlAttrs
};
return [p, a];
}),
elem('text').attrs()(function() {
var a = applyNext() || {};
a.id = this._textId;
a['aria-hidden'] = true;
return a;
})
); After: block('button').match(function() { return this._attachButton; })(
{
tag: 'span',
def: function() {
return applyNext({
_name: this.ctx.name || 'attachment',
_id: this.ctx.id || this.generateId(),
_textId: 'text' + this._id,
_tabindex: this.ctx.tabindex
});
},
attrs: {}, // принудительно сбрасываем все атрибуты
content: function() {
return [
applyNext(),
{
block: 'attach',
elem: 'control',
attrs: this.ctx.controlAttrs
}
];
}
},
elem('text')({
attrs: function() {
var a = applyNext() || {};
a.id = this._textId;
a['aria-hidden'] = true;
return a;
}),
match(function() { return !!this._disabled; })({
mix: { mods: { disabled: 'yes' } }
})
); @veged @zxqfox @arikon @tadatuta it’s real template from islands. Many combinations with compositions and chains, many objects literals. The result is very difficult to read and maintain. |
I can't agree ;-) |
After (using all existing features in 8.x): block('button').match(n => n._attachButton)(
{
tag: 'span',
def() {
return applyNext({
_name: this.ctx.name || 'attachment',
_id: this.ctx.id || this.generateId(),
_textId: 'text' + this._id,
_tabindex: this.ctx.tabindex
});
},
attrs: {}, // принудительно сбрасываем все атрибуты
appendContent() {
return {
block: 'attach',
elem: 'control',
attrs: this.ctx.controlAttrs
};
}
},
elem('text')({
addAttrs() {
return {id: this._textId, 'aria-hidden': true};
},
match(n => n._disabled)({
mix: { mods: { disabled: 'yes' } } // Is this `{block: ?, mods: {disabled: 'yes'}}` ?
})
})
); It has much less noise. |
Such syntax is most clear in my opinion. |
I have been trying to program such shortcuts. In general, my changes is:
Example 1: with shortcut: block('b')({ tag: 'a' }) without shortcut: block('b').tag()('a') Example 2: with shortcut: block('b')( mix()('mixed'), { tag: 'a' } ) without shortcut: block('b')( mix()('mixed'), tag()('a') ) Now we have such templates: block('b').addMods()({ first: 'yes' }) Current version just add modifier There is two way to do:
|
I suggest |
And also already in Turbo! |
Before:
After:
Before:
After:
Complex cases gonna be like this.
Before:
After:
Some cases gonna be only in old syntax:
The text was updated successfully, but these errors were encountered: