bem / bem-xjst

bem-xjst (eXtensible JavaScript Templates): declarative template engine for the browser and server
https://bem.github.io/bem-xjst
Other
116 stars 48 forks source link

Multiple elems for the same templates #138

Closed vithar closed 8 years ago

vithar commented 8 years ago

I have this code in my project:

block('regions')(
    elem('region')(
        tag()('span'),
        match(function() { return this.ctx.url; })(
            tag()('a'),
            attrs()(function() { return { href: this.ctx.url }; })
        )
    ),
    elem('currency')(
        tag()('span'),
        match(function() { return this.ctx.url; })(
            tag()('a'),
            attrs()(function() { return { href: this.ctx.url }; })
        )
    )
);

As you can see, templates for region and currency element the same. Can we implement support for multiple arguments in elem (e.g. elem('region', 'currency')) or ability to pass array as argument (e.g. elem(['region', 'currency']))?

tadatuta commented 8 years ago

@vithar see https://github.com/bem/bem-xjst/issues/135

blond commented 8 years ago

@tadatuta why not make multi-selectors like in CSS with , delimiters?

For elems:

block('regions')(
    elems('region', 'currency')(
    )
)

For blocks:

blocks('regions', 'smegions')(
)
vithar commented 8 years ago

+1

miripiruni commented 8 years ago

@vithar take a look at https://github.com/bem/bem-xjst/pull/165

Isn't enough elemMatch()?

vithar commented 8 years ago

It is enough, thanks.

blond commented 8 years ago

So, what about multi-selectors?

tadatuta commented 8 years ago

@blond that's too rear case to provide such sugar

blond commented 8 years ago

@tadatuta, sugar affects performance?

tadatuta commented 8 years ago

it extends API without necessity