Comments (10)
@apsavin's proposal in diff format:
' return exports;\n' +
' }\n' +
' var defineAsGlobal = true;\n' +
- ' if(typeof exports === "object") {\n' +
- ' exports["' + exportName + '"] = __bem_xjst({}' + modulesProvidedDeps + ');\n' +
- ' defineAsGlobal = false;\n' +
- ' }\n' +
' if(typeof modules === "object") {\n' +
' modules.define("' + exportName + '"' + modulesDeps + ',\n' +
' function(provide' + modulesProvidedDeps + ') {\n' +
' provide(__bem_xjst({}' + modulesProvidedDeps + ')) });\n' +
' defineAsGlobal = false;\n' +
' }\n' +
+ ' else if(typeof exports === "object") {\n' +
+ ' exports["' + exportName + '"] = __bem_xjst({}' + modulesProvidedDeps + ');\n' +
+ ' defineAsGlobal = false;\n' +
+ ' }\n' +
' defineAsGlobal && (g["' + exportName + '"] = __bem_xjst({}' + modulesProvidedDeps + '));\n' +
'})(this);'
from bem-xjst.
this change will break backward compatibility.
maybe we'd better provide build options for user to choose?
// cc @blond
from bem-xjst.
@tadatuta exactly, thanks.
If you don't want to break backward compatibility, you can just check typeof
of provided deps and if they are in the global scope - export BEMTREE
in node.js way, if not - in ym modules way only. No need for new build options.)
from bem-xjst.
Do you want a PR?
from bem-xjst.
@apsavin I'm not sure I understand the way you want to handle backward compatibility.
But if it'll be really so, why not ;)
from bem-xjst.
@tadatuta can you please take a look on PR #61 ?
from bem-xjst.
@apsavin, we plan to change way to require dependencies in enb-bemxjst
— enb/enb-bemxjst#61. What do you think about this?
from bem-xjst.
To be honest, I think that #61 is all what I need.
I don't like this.lib.blah
way to use templates deps. Templates is the place where I don't want to write too much.
Shortcomings
It is impossible get the module from global scope.
It is impossible get the module using CommonJS.
Interface expects variables from global scope.
- I don't think it's a problem. Why do you want to use BEMHTML/BEMTREE from global scope?
- Will be fixed after #61 will be merged
- Sorry, can't get it(
from bem-xjst.
I don't think it's a problem. Why do you want to use BEMHTML/BEMTREE from global scope?
We are about to get variables from global scope optional for CommonJS or YModules.
Will be fixed after #61 will be merged
No, this PR provides an opportunity to get module from global scope if use CommonJS, but there is no way to use require('path/to/module')
.
Interface expects variables from global scope.
It is that the template used variables that are taken from nowhere: https://github.com/bem/bem-core/blob/v2/common.blocks/i-bem/i-bem.bemtree#L1
I don't like this.lib.blah way to use templates deps.
Can you suggest how to write more briefly, but not use variables from global scope?
Example, for the new i18n
would be used this.i18n
, instead BEM.I18N
.
block('block').content()(function () {
return this.i18n('block', 'key');
});
Maybe we should do the same with custom dependencies?
block('block').content()(function () {
return this.vow.resolve('ok');
});
from bem-xjst.
well, this.libs.vow
sounds better than this.vow
.
But I don't thinks it's too bad to declare something as global variable for templates. All templates - BEMHTML, for example - is just one ym-module with some deps. Of course, those deps are "global" for the module. I can say more, I see almost no difference between global variables in this.libs and global variables just in the scope. I think, we should keep templates as simple and convinient as possible.
Now I can add global functions for BEMTREE/BEMHTML very easy and I like it. For example, I can provide global function path(route_id) // returns url
and use it like this:
{block: 'link', url: path('some_route')}
And I think that force users to write this.libs.path
every time is ugly and bad idea.
Hmm, I'm afraid we lose some part of understanding because of English.
Can we solve mentioned above problems without forcing users to use this.libs.lib
instead of lib
?
from bem-xjst.
Related Issues (20)
- runtime-lint/index.js not found HOT 2
- Incorrect linter "someone changed ctx.mods" HOT 2
- Update bem-xjst in online demo
- Очередность применения шаблонов для элемента при указании `block('*').elem('*')` HOT 4
- Производительность движка в некоторых случаях можно увеличить HOT 5
- docs: Wrong default value for exportName in `3-api.md` HOT 2
- [online demo] Migrate from URL Shortener APIs to Firebase Dynamic Links (FDL) HOT 1
- bem-xjst 7.7.6-7.7.7. Увеличен размер бандла bemtree и bemhtml на клиенте
- Docs: insure all add* modes are present in docs
- attrescape: should escape `<` and `>` HOT 1
- Tree Shaking for templates (like CSSO for bem-xjst)
- attrescape: Do not escape & HOT 3
- Prevent multiple calls of add* methods on the same node
- Question about difference with 7.x behaviour
- Benchmarks: missing dependencies, broken link in documentation HOT 3
- Nested mixes are duplicated
- Nested mixes as BEMJSON are not processed HOT 1
- Nested mixes work wrong with strings HOT 1
- Не работает BEM-XJST Demo
- How to compile css style rules with component/block etc.?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bem-xjst.