-
Notifications
You must be signed in to change notification settings - Fork 9
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
added icon plugin #26
Conversation
According to the API doc:
When is this plugin supposed to be used? Is it part of a build step, rather than being used when the application runs? |
I was conveniently burying the complexity in that one sentence but you're right, it should be more specific. You start by writing this in your application define([
"requirejs-dplugins/icon!./icon1.svg",
"requirejs-dplugins/icon!./icon2.svg"
], function(){...}) The code of this plugins runs in 3 situations
|
OK, that makes it clearer. But why create a sprite.svg file rather than just inlining the SVG text into the layer's JS files, the same way as the
That went completely over my head. Is this about not repeating the same block of SVG on the page 10 times? |
It seemed to me the only reason we went for wrapping templates in js module is so that we can concatenate them during the build then fetch them all in one file, and html offers no other way to do it. SVG does so I went for it.
The SVG markup of some simple icons can get very big (example), the fact that the sprite is built using |
IIUC, at runtime your plugin loads the icons (or sprite) using the I understand how the Relatedly, the tests you've written are all checking the sprite, which is sort-of an implementation detail. You should have basic tests from an end-user perspective, i.e. test that the icon is available after the plugin finishes loading. The other thing, which I think I've mentioned before, is that if this plugin and the |
Yes. We plan to use it in other contexts. |
I think having pure svg layer give additional value since it would allow someone to load the svg without requirejs. So it is a more agnostic solution than inlining the svg directly in the requirejs-specific layer. But I agree with you that there is some duplication in the build code for the various plugins. When I get some time I will try to refactor this in a shared module providing build utilities. Regarding the tests, I think testing the structure of the sprite is enough. The actual binding using @tkrugg A sample use of the plugin would be welcome ;) |
@@ -4,7 +4,8 @@ | |||
"description": "AMD plugins for RequireJS", | |||
"dependencies": { | |||
"lie": ">=2.8", | |||
"requirejs": "2.1.x" | |||
"requirejs": "2.1.x", | |||
"text": "requirejs-text#2.0.14" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test that the mapping of requirejs-text to text does not break anything when used with delite for example ? Also could you change the version used to 2.0.x so we keep consistency with other ibm-js projects.
That sounds like a stretch. Our whole architecture and even this plugin itself is based on AMD. This design is adding pages and pages of code with no regression test.
And I say, don't test the structure of the sprite at all, because that's an implementation detail. Just test that the icons get loaded. |
What do you propose to check that the icon loads ? I have not been able to come up with a better way than testing the sprite. Also I don't think the sprite is an implementation detail but the main output of the plugin. According to the plugin documentation:
So I would rather see the sprite as the interface for the user to load an icon than an implemention detail. |
Well, the icon.md documentation says that the user is supposed to do
I'm not sure what you mean. The interface to load the icon is One thing that's unclear is what href to use. Is it based on the file name? That seems weak, because you could easily have two icon files with the same name. I would expect instead this interface:
Side note: |
|
||
// Write layer file and config | ||
var success = buildFunctions.writeLayer(writePluginFiles, dest, loadList); | ||
if (success) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think success can be false in this plugin. Maybe you can remove that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure.
But isn't that true for css as well? I'm just wondering what could fail with css.js in comparison
I think something like this makes sense: https://github.com/wkeese/requirejs-dplugins/blob/3de62c53ce3feb7a2ed2855677e0a07049bc4814/icon.js. It's less than half the size of the original code, and will also load quicker because there's one less network request. OTOH, if you stick with the current design, then you need to add a lot more tests, such as when there are multiple sprites, and when there's a sprite but also some icons are loaded individually. |
I like your idea of leveraging the text plugin, I wasn't aware of it, and it is impressively lowering the size of the plugin. Thanks for taking the time to explain and implement what you meant, I really appreciate. I can think of a few functional differences:
|
That's a good analysis. I agree there are advantages to do parsing at build time... The Speaking of parsing, the current svgSprite.appendChild(iconFileDOM.querySelector("symbol"));
That's true for some of the code, but not all, in particular code in common.js. BTW, it seems like you shouldn't have a separate file called common.js since it's only used by icon.js. |
PS: What I wrote above about I also noticed that all your example icons have a single |
I've done some changes but i've put them in another branch https://github.com/tkrugg/requirejs-dplugins/pull/1. i'll merge it into this one eventually. |
(copying my comments from the other PR...) Thanks for the simplifications. The definitely makes it easier to compare approaches, and I like how it's sharing more code than before. One thing though: at runtime, it makes sense to call Relatedly, I'm unclear what happens when you load (for example) two pre-built sprites (each containing 10 icons) and two stand-alone icon files. What DOM do you end up with? A single Minor note: Might want to combine |
Yes the sprite is loaded as one big icon. For example if the <svg>
<symbol id=icon1..>
<symbol id=icon2..>
<symbol id=icon3..>
</svg> And this svg file can be loaded like any icon and the markup in the browser will look like: <svg style="display:none">
<symbol id="layer.min">
<symbol id=icon1..>
<symbol id=icon2..>
<symbol id=icon3..>
</symbol>
</svg> Note that this isn't weird at all. It's totally normal to combine symbols to create other symbols.
|
I see, that's a reasonable argument. One issue I notice is that That reminds me about the problem I mentioned earlier about when two icons have the same id because the have the same filename, for example deliteful/Combobox/arrow.svg and deliteful/DropDownButton/arrow.svg. It would be nice to resolve this somehow. A related consideration is the corner case when the app sets up a AMD map to (for example) load two separate versions of deliteful/Combobox, with corresponding icons d1/Combobox/arrow.svg and d2/Combobox/arrow.svg. |
- a few ajustments in svg plugins atfer clement's feedback - enhanced last unit test - Added missing onload when building
I think the plugin should return the id of the svg graphic requested. This may be the file name of the svg or the content of the id attribute on the symbol element. The tricky part is to keep the binding between requested file name and icon id when we load the sprite.
I don't think this is an issue as it can be solved by using different ids in the svg markup.
I don't see a work-around for this one, but I am not sure there is much we can do about it. There would be the same issue if the two Combobox use the same CSS class names with different implementation. Since all CSS is gloabal one stylesheet would override the other. Since we have come to minor issues and we need to make progress here, I am merging this in e76c16d and opening defect #29 to track the issue with returned value when loading sprites. |
I'm disappointed you checked this in. As I mentioned already I question the whole design with generating a separate sprite file. It leads to many complications. |
What if there are two separate packages from separate authors that both have a file called arrow.svg? For example, like dijit and idx. And then there's some app using both of those packages? This is the basic concept about why global variables are bad, and relatedly, why we have namespaces (for example java.lang.xyz) or AMD paths (example deliteful/Combobox) rather than just global names like xyz and Combobox. |
Since you already closed this ticket, I filed #30 for the problem with duplicate ids. In that ticket I explained why adding explicit id's to icon files doesn't solve the problem, and instead, list multiple ways that you can solve the problem. From your actions, it's clear that you are rushing to start using this plugin before it's finished, but that's a bad idea, because the API is going to change. Specifically, you need to get the icon's id from the return value of the |
No description provided.