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
Feature suggestions and a question #41
Comments
Thanks for the request!
Regarding the question, you can simply use <div id="app">
<ul>
<li m-for="segment in {{trip.segments}}">
<p>Origin: {{segment.origin}}</p>
<p>Destination: {{segment.dest}}</p>
<p>Date: {{segment.date}}</p>
<p>Departs: {{segment.departs}}</p>
<p>Arrives: {{segment.arrives}}</p>
</li>
</ul>
</div> new Moon({
el: "#app",
data: {
trip: {
segments : [
{ origin:"MIA",dest:"MCO",date:"09SEP17",departs:"0800",arrives:"0852"},
{ origin:"MCO",dest:"ATL",date:"09SEP17",departs:"1020",arrives:"1115"}
]
}
}
}); Here is a jsFiddle link |
Excellent...I'm going to work up a POC for the airline thing. (It's relevant to work.) I definitely wouldn't attach get/set to deep items, although there's a cheat (kind of):
The experiment I did was in gathering all specially-marked items in a page via querySelectAll, and adding them as members of an overarching Page.View object.
then queued an update for the page, which ran in either an idle callback or animation callback. I didn't get far enough into it to see how well it scaled, but it was part of a plan that would let the page designers do the layouts and mark the active fields with data- attributes, after which time the coders would come in and connect the dots, so to speak. It's only the kind of thing I'd do with cheap look-ups in the model. |
Cool! Here's a little plugin that does a shallow run through of the data, and proxies it to the instance, for all Moon instances automatically: var MoonTracked = {
init: function(Moon) {
var init = Moon.prototype.init;
Moon.prototype.init = function() {
var data = this.$data;
var self = this;
var track = function(key) {
Object.defineProperty(self, key, {
get: function(key) {
return data[key];
},
set: function(val) {
self.set(key, val);
}
});
}
for(var key in data) {
track(key);
}
init.apply(this, arguments);
}
}
}
Moon.use(MoonTracked);
var app = new Moon({
el: "#app",
data: {
msg: "Hello Moon!"
}
});
app.msg = "Changed!"; <div id="app">
<h1>{{msg}}</h1>
</div> Here is a jsFiddle |
Thanks--I'll check that out. Meanwhile, it doesn't like this:
(unknown) Uncaught TypeError: Cannot read property 'seats' of undefined Does the inner m-for not have a context for pax? The examples don't have any nested loops, but neither do they seem to be prohibited. The data from the server will always have seats as an array embedded in another object, so access to previous m-for temporary handles would be necessary since the seats can't be referenced without context to another iterated entity. (I haven't looked at the Moon code to see if the m-for proxies are kept in a stack. That would help resolve the issues.) Because the table column count varies based on the number of itinerary segments, I have to put in a tag pair (mimicking the very convenient ) to support writing a variable number of instances into the row. That makes me vaguely uneasy, and it probably wouldn't validate, but it seems to be the only thing I can do. (Yeah, tables. Passe', but the accessibility requirements set forth by the Americans with Disabilities Act pretty much sum up to "novel approaches to layout are nice for everyone else, but the cool kids use tables for accessible content to avoid confusing screen reader plug-ins"). [If this turns out to be a typo on my part I'm going to be very annoyed at myself.] |
Moon does allow nested I think this is because of the table. Before going through Moon's compiler, the HTML is normalized by the browser, and it is removing the As an alternative, try Also, as far as I know, |
Yeah, I think the reason I went with putting the m-for in the tbody is that I'm thinking like a programmer: "the m-for is repeating what's in the tbody, not the tbody." (The m-for should be on the tr, but that's not what occurred to me the first time. But I see a 'for' and I'm all about the loop body--which isn't what happens here. Have to kick my brain into a different gear for the markup.) At least it wasn't a typo. The other reason I was thinking that way is that I wrote a server-side C++ framework 16 years go in which I added new tags to html (
(The framework kept track of the indexing internally.) |
It's not pretty but pretty wasn't the goal. Thanks! |
Love it! 🙌 |
So, another question (because they don't end, right?): if I try to render a seat map, I'm going to have to apply all sorts of styles to the element based on class of service, taken/open, travel partner, wing, exit row, etc. That seems a bit of a push to implement with m-if and otherwise static markup. It seems like a callback might be required to apply classes to the to-be-rendered element. I didn't see any support for callback functions on a per-element basis in the docs, but I could have missed something. |
There is a cleaner way to conditionally apply classes to an element via <h1 id="app" class="{class1: {{condition1}}, class2: {{condition2}}}
new Moon({
el: "#app",
data: {
condition1: false
condition2: true
}
}) See the |
Yeah, except that it has to be done for every seat, and I didn't figure to have to reset the data for every seat. If conditions 1 and 2 could be functions from which the true/false result was captured. (Likewise, adding an extra field for 156-300 seats would be computationally debilitating.)
One usually shows only a single cabin at a time, so that makes it easier. I already have code that can compose a seatmap with straight-up DOM--so I could hide it behind a class instance that just took a DOM element ID and used it--but I thought I'd try to do a performance test using Moon. One means of building the page would be less confusing for the team--especially incoming members. |
Ahh, I see. In v0.10.0, there will be different scoping (there will be no mustache templates inside of directives and For example, in v0.10.0 you will do something like: <div id="app">
<h1 id="{{dynamic}}" m-literal:class="{class1: condition1, class2: condition2}">Hello Moon!</h1>
<p>{{1 + 2}}</p>
<ul m-if="list.length > 0">
<li m-for="item in items">{{item}}</li>
</ul>
</div> As you can see, when using This will allow you to use a custom method to decide what class should belong to which seat. You can do something like (in v0.10.0): <div id="app">
<ul>
<li m-for="seat in seats" class="{{ getClass(seat) }}">
{{seat}}
</li>
</ul>
</div> new Moon({
el: "#app",
data: {
seats: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
},
methods: {
getClass: function(seat) {
if(seat > 5) {
return 'red';
} else {
return 'blue';
}
}
}
}); .red {
color: red;
}
.blue {
color: blue;
} You can use this custom method to dynamically return a class name (or |
That would be exactly the thing. Except (as a C++ programmer) functions with variant return types make me nervous (and if TypeScript is ever involved, it will be unhappy as well). Empty strings would work as well as |
Totally get it, an empty string will work as well 😉 |
I removed the milestone for making Maybe add a new method that can merge an object? (Like React's Let me know what you think. |
It comes down to code size. If one compiled JavaScript, then the source code size doesn't matter. Minification isn't going to resolve the size issue for multiple calls, either, because one still carries the overhead of the smallest possible variable name, plus the de-reference. It seems to work well enough for JQuery. Plying me with React will get you nowhere. I don't like React. :) That's why I'm interested in Moon. One thing lacking in your conclusion is the word "because," followed by more words. What is the negative impact of chaining for this method? The Experienced Guy wants to know! (Since software engineers are usually required to explain things, rather than cite "feelings.") |
Well, it leads to a smaller bundle size: // Normal
a.set('count',1);a.set('msg','Hello')
// Chained
a.set('count',1).set('msg','Hello')
// Object
a.set({count:1,msg:'Hello'}) I also feel like the object syntax looks cleaner, instead of chained calls to |
This issue has been inactive for a while, let me know if you are still interested in this being added to Moon. |
I'm good with how you want to do it. |
With the object syntax? |
Yes, if I really feel the need to chain or supply multiple updates I can do
it with a function.
…On Fri, Jul 14, 2017 at 12:13 PM, Kabir Shah ***@***.***> wrote:
With the object syntax?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#41 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABiIfMS6FKRA9CW3e8GljtEbMDarqEL-ks5sN5OmgaJpZM4NMQIQ>
.
|
Alright, I can add this as a feature in the next version. |
@kingpixil
|
@oanhnn Thanks!
|
I think these three things help expand the
|
Thanks for the tips, glad you want to expand the community. I don't have much time to move all of Moon's repos to an organization right now, or to port syntax highlighting to other editors. (I also don't have a way to test if they work). Porting to sublime should be easy enough, and if you know any people who actively use Moon and would like to take it on, be sure to let them know! |
(Finally) fixed in d81083c |
Features:
Item 2 brings me to a question: if my application has (for example) flight segments to be rendered
then what does the HTML look like to render that in Moon? (I couldn't make it work the way I wanted to in Vue, and mustaches don't seem to lend themselves to it.) Overall these frameworks seem oriented toward single-field renders or (at best) single-column data amenable to UL rendering. Can't quite get my head around complex data rendering for these things.
The text was updated successfully, but these errors were encountered: