« first day (419 days earlier)      last day (4512 days later) » 

1:00 AM
adding listeners to Collection s? or models ?
 
@tereško unless npm has libraries that make it easy I would recommend learning erlang instead
 
i just need to the this framework-thing out of my system
 
@Raynos: are you serious :p ? you're skipping quite a lot
 
@jAndy it's because I don't understand what's going on :D
 
well each view instance that represents a model instance should of course listen to the corresponding model state changes
 
1:01 AM
no events fired
 
@Raynos its a tick-based browser/mobile mmorpg concept .. i am pretty sure NPM will not have what i need
 
so the .set calls aren't being fired then
 
@Raynos: you probably should me let do that refactoring :p or wait until I wrote a proper doc
seriously :P
 
Nah
it's cool.
Im reducing the code a lot :D see its working
 
1:02 AM
I don't think so :p
not if you want to stay on track with the original architecture
 
I'll stay on track with the architecture all right
 
   parse: function(response)
   {
       console.log( this.models );
@MianKhurramIjaz, add that log and see what gives
 
@jAndy fixed
 
1:05 AM
Empty
[ ]
 
@Raynos: I thought you might trolling
 
that means there are no models in the collection :P
 
@jAndy no I'm seriously trying to refactor it. First out with the old, now in with the new
 
ok
i think we are in process of adding models to collection in parse: fucntion ?
 
yea
remove the whole parse function, it should work if the response is a direct array
 
1:09 AM
this.each(function(model, index) {
console.log('models are '+model);
model.set({
name: response[index].name,
content_type: response[index].content_type,
bytes: response[index].bytes,
token: response[index].token
});
This never gets called ?
 
it doesn't get called because it has no models :P
 
ok
so
the view is still not rendering
 
@Raynos: so far the refactoring looks like joking and insulting :p
 
forget the view for now. you aren't even populating the collection yet
 
@jAndy I'm actually being serious but throwing in a healthy dose of tongue in cheek mockery
 
1:12 AM
oh i c ... :) strangely why the call does return showing response from my server
 
just remove the parse method altogether
 
it is removed
 
after your page is loaded and the fetch is done
manually open developer console and write console.log( myCollectionInstance.models );
and see if its populated
@Raynos lol you even deleted the licence.txt
 
@Esailija I did? xd
 
it is not defined
 
1:18 AM
@MianKhurramIjaz, what holds the instance... use that myCollectionInstance is just an example..
 
i know i tried with myfileCollection.models
 
yes but it's a local variable inside the onClick function
it's not known in the console global scope
and you can't just log it right after either because it's asynchronous
 
hmm
so should i declare it out side so that console can know what is inside him
i c
:)
 
var res = myfileCollection.fetch({
    data: {
        name: name,
        token: token
    },
    success: function(coll) {
        console.log(coll.models);
    }
});
@MianKhurramIjaz, just do that it will log after the request is complete and the models added if they were added at all
 
yes
it works
log is showing json objects
so would the change event will fire now ?
 
1:24 AM
yes now u can iterate the models as well
 
coll.each ( function( model ){ new MyView({model: model}); ...} )...
 
and i put the same parse code inside the fucntion() {...} yea?
 
no no parse
 
:
)
/
pars?
 
1:26 AM
see now that the collection is populated with models, you create views that represent those models like above
 
coll.each ( function( model ){ new MyView({model: model}); . what is here ?..} )
 
the three dots just mean stuff that I left out because I have no idea what you are trying to accomplish =D
 
Esailija you are the best person i have ever sought help from . please have a look at the updated code and all i want is the view to show the 3 files in three different lines and thats it
all i want is when ever i make a fetch call the view should be updated with the new contents from the server
Esailija if you have a donation box i dont mind making transaction of small gift for this help :)
 
@MianKhurramIjaz, try this I made a new view jsfiddle.net/gRD6N/8
oh just remove fv =
        coll.each(function(model) {
            new myFileItemView({
                model: model
            });
        });
 
1:38 AM
content_type is not defined
[Break On This Error] var func = new Function('obj', '_', tmpl);
i think this is the problem of the template now
 
ah ok let's see
I didn't pass the model attributes to template :P
 
@MianKhurramIjaz, in myFileItemView change
var template = _.template($("#file-item-template").html(), this.model.attributes );
 
Node cannot be inserted at the specified point in the hierarchy
[Break On This Error] (b[1]=(b[1]||"").toLowerCase(),b[3]=b[...h){var a=this.pushStack(this,"after"
 
add console.log( template ) in the above code and see what the html is
 
1:41 AM
how strange is this message ?
it is undefined
 
ok.. add console.log( this.model.attributes )
you see where I am going with this right?
log your shit
:D
 
hahaah :)
ok.. add console.log( this.model.attributes ) gives json objects workign good
 
hmm
did you try to log template after or before var template = _.template($("#file-item-template").html(), this.model.attributes );
 
yes
i didi
it was undefined
 
you logged it AFTER ? right ? then the template is not working
 
1:46 AM
template is working well
it is generating the <td></td> all of them but only for one fie
 
then there was only one model in the collection I think
if it's working good but only for one file?
You can see how many there are:

success: function(coll) {
                console.log(coll.models.length);
 
Hi
 
all good the IT DISPLAYED THE ONE FILE ATTRIBUTES ALL RIGHT
i loving it today
 
so I have a click function on a li
 
OH MY GOD
it is working so perfectly fine i removed the line .append()
 
1:49 AM
i want to select the nested ul when it is clicked
but this is returning [object DOMwindow]
instead of [object HTMLLIElement]
window.event.target works, but doesn't let me select the inner ul
 
@Purmou, jsfiddle.. and just of the click handler please. no whole code base =)
 
.length = 3
 
@Esailija I'm coding this for an answer, so don't worry about that :p
 
and now it is showing all the 3 generated tempaltes in log as well but it only shows one of them in the view
and it works
 
@MianKhurramIjaz, ok so the problem is with append
@MianKhurramIjaz, you are very close now they just need to be added all somehow :D
 
i removed the append and it is working other wise it gives node can not be inserted errror
yes
 
@Purmou, this is only the element in the onclick handler not the global function
 
@Esailija ...what did you ask for?
 
Esailija i think the view is only updated once and the other calls are not updating the view could that be it is only showing one file
 
1:53 AM
@MianKhurramIjaz, no there are 3 separate view instances
 
@Esailija wow, lol it was that easy? xD
 
yeah but each of them have one file
 
yes, they each represent a single file. hence the name myFileItem
 
it is showing the last one only
 
so the last one is overwriting the 2 ones before
 
1:55 AM
exactly
 
@MianKhurramIjaz, show me the codez
@Purmou, yes but onclick in html is really bad
 
@Esailija Should i use li.onclick = function(){
 
yeah but with domReady not wrap head
 
1:57 AM
@MianKhurramIjaz, like I said before, you need a new view... all the 3 views are using the same element because of el: $('#gs-file-list')
they all are the same element
 
@Esailija how do I specify it for every li? Because there will be more than one
 
well that is how backbone is designed it is a container and all the objects should be listed here
its a table with tr and td
then we do need to .append it
 
you can't append it because it's the same element
 
@Raynos: looks ok with regards to the content. not sure what .emit() is going to be.
 
then we append to the table ?
 
1:59 AM
@jAndy .emit === .dispatch
 
$(this.el).append(template);
try that
html will just replace
 
all loaded in a single line thogh
the rows are missing
i add the tr in the tempalte now
 
@Purmou, make a jsfiddle ill edit it
 
WOW
finsihed
ALL DONE
 
Well why is HTML onclick bad?
 
2:02 AM
how can i pay you Esailija
i love to send you some thing in return
 
@MianKhurramIjaz, read the tutorials
:D
 
my email is khurramijazm@gmail.com please please contact
 
@Raynos, can you explain why HTML onclick is bad
 
what tutorial did you read ?
 
you can start here backbonetutorials.com
 
2:03 AM
@Purmou because you are mixing the layers of web : content with behavior
 
I love it when raynos does it... with passionate rage
 
javascript has no place in html
 
@tereško okay, how would I run a function when any li is clicked?
 
additionally , using onclick make the code harder to maintain , and , if you have a lot of instances of onclick in your document , you will be slowing the page down
 
2:04 AM
document.getElementsByTagName("li").click doesn't work
 
well .. thats where learning comes in
you cannot just make shit up and hope that it will work
 
i learned getelementsbytagname and thought it would work...
 
[].slice.call( document.getElementsByTagName("li") ).forEach( function( elem ){
elem.onclick = function(){alert( "hello world" ); };
});
 
is there really a problem?
it's experimentation
 
@Esailija ragequit
 
2:05 AM
i learn better when reliable people tell me it's wrong and explain to me why, and how to do it right
 
@Purmou, understand my code and you will be ahead of the pack :D
 
@tereško though you'll be happy to know i've been trying my best to use pure JS when I can...
in fact I gave a pretty decent answer the other day:
 
6
A: JQuery select element if *any* attribute matches

Purmouvar elements = document.getElementsByTagName("*"); for(var i=0;i<elements.length;i++){ var element = elements[i]; var attr = element.attributes; for(var j=0;j<attr.length;j++){ if(attr[j].nodeValue == 'author'){ element.style.backgroundColor='red'; } ...

 
first of all , @Purmou , getElementsByTagName returns a list of DOM elements second - thats not a proper way of attaching events .. and third , but not least , if you you want to attach event to multiple elements ,then you should use *event delegation
 
2:07 AM
@tereško depends, sometimes you do want to attach events to multiple elements, 90% of the time you want delegation
 
and never fucking EVER write this : var elements = document.getElementsByTagName("*"); for(var i=0;i<elements.length;i++){}
NEVER
 
lol there's the rage
 
@tereško 0.o
some people in this chat told me to do it that way...
 
my day is made
 
document.getElementsByTagName("*") result is not an array
it is a Element Collection
 
2:08 AM
@jAndy I could totally write the dom-shim as a Raynos/BarFoos module :)
 
each time you access elements.length , it will recalculate said lenght
 
so why does it work?
i'm only accessing it once though, for the for loop
 
...
 
even worse , if you start adding tags in such loop , it will go on for ever , because length will always change
 
Thats not how a for loop works
the i < elements.length has to be calculated at each step
 
2:10 AM
hmm
good point
is there a toArray function in JS? xD
 
Yes
 
there is ?
why do we bother with slice call then
 
function toArray(obj) {
  var arr = [];
  for (var i = 0, len = obj.length; i < len; i++) {
    arr[i] = obj[i];
  }
  return arr;
}
The amount of times I have to write that utility :\
it annoys me.
its the one utility function I use everywhere
Mainly because it's about 100% faster then [].slice.call
 
[object Nodelist]
 
that goes so much against intuition that i have to test it
 
2:12 AM
this is what I get for TagName("*")
 
aaaarrrgh ... how i hate the twitter feedslike "want to learn more about cakephp .." , no , do not want , stop retweeting the crap
@Purmou which is not and array
 
@tereško how do I differentiate?
 
none of the document.getElementsBy****() functions returns an array
you just learn it , and remember it
 
got it
thank you
 
@tereško Y U ADD PHP NOOBS ON TWITTER
 
2:15 AM
Esailija: how to empty the old_view
 
@Purmou dom returns either NodeList or DOMCollection never Array
 
or DomElement ( in case of getElementById )
its what you get when you leave Java developers alone to create DOM spec
 
@tereško Element
Or more specifically HTMLElement
Turns out it's HTMLCollection not DOMCollection
 
well .. names doesnt really matter
 
HTMLCollection is a legacy thing anyway, you wont see it much
Interesting, HTMLCollection.prototype.isPrototypeOf(document.children)
 
2:21 AM
@Raynos, seems about the same with huge array-like jsperf.com/slice-call-vs-manual :D
 
@Esailija congrats on only testing one browser -.-
 
I tested with smaller arrays on many browsers
but manual was faster in those
cos they were small
 
Fair enough
Most of the time I clone small arrays
use arrays is an edge case
the reason small arrays are faster is dont know
 
most of the time I don't need to convert 10 million arrays a second
.slice is a property lookup
toArray is just direct function
that could affect it
 
ok , NASA called , they want the supercomputer back from the guy who runs opera 11.51 on it
 
2:25 AM
I mean .call is a lookup
and you cannot cache it afaik so :(
but it's really micro optimizations, slice call is not so slow that you'd deliberately want to copy paste a new function or include one
 
its not really a micro-optimization if you are using it all the time , and there is 2x difference
 
seeing at is still takes sub microsecond, it's a micro-optimization
and it's not exactly a thing that you need to do hundreds of thousands of times per second anyway
 
@Esailija told you dyi was faster :D
@Esailija caching call is easy
var slice = [].slice.call.bind([].slice);
 
but the whole point of caching is lost there
you now make 2 function calls everytime
and possibly call slice inside the bound function to pass arguments on etc
I guess firefox and chrome somehow optimize it though? Giving me same results as slice.call
If that were a home made bind function it certainly would be a lot of slower
 
2:36 AM
@Esailija you only make two function calls if you emulate bind
 
why on earth does dart create its own bind functions if the native bind is so optimized
 
@Esailija Makes it more dartacuarl.
 
@Esailija trolls? I mean dart is a piece of shit
What did you expect?
 
lol wtf check this out jsperf.com/slice-call-vs-manual
it has bind, homemadebind, slice.call and DYI
for one test the homemadebind got 20k more operations in :D
than native bind
 
@Raynos but obj isn't an array so why get its length? isn't that what teresko was bugging me about?
 
2:44 AM
@Purmou obj is an array like. All array likes (argument, NodeList) have a .length property
 
so why was @tereško bugging me about how document.getElementsByTagName("*") doesn't return an array?
 
in firefox also, homemadebind is faster than native bind. Wtf is going on @Raynos :D
 
@Esailija jsperf isnt that reliable
dont fret it
 
that's the only explanation that will keep my sanity :P
 
@Purmou it doesnt return an array. An array is an instanceof Array an array like is an object with numerical indexed properties and a property name length
 
2:46 AM
congrats , @Purmou , you managed completely ignore the point .. maybe you should change the hobby .. try politics
 
@tereško you always manage to insult me...what's your problem?
 
@Purmou , it's the rage... don't take it personally :D
 
i'm here trying to learn and you just trample all over me all the time
@Esailija he's done this before...lightning doesn't strike the same place twice. except teresko's
 
it's a severe allergic reaction to willful ignorance and stupidity
 
@Purmou his problem is you dont understand stuff quickly enough :3
He's saying @Purmou Y U NO COMPETENT >:(
 
2:48 AM
someone link me to their original convo?
 
let's try this again
 
Dont fret it. I aint competent either, and @tereško is far from competent wrt javascript
 
an object can be like array but not be an actual array
 
I'm fine with criticism, but when he outright insults me twice it becomes an issue
seriously?
 
@Purmou My attitude is tongue in cheek humor. His attitude is allergy to incompetence. Don't take it personally
 
2:49 AM
47 mins ago, by Purmou
Well why is HTML onclick bad?
 
@Raynos all right
 
@Purmou btw try Array.isArray on objects
it will tell you whether they are arrays
 
@tereško I apologize deeply, your highness, for asking a question not worthy of your attention.
 
Array.isArray(document.all); // false Array.isArray([]); // true
 
and he missed the point ( or this time , the arrow ) again
 
2:51 AM
the arrow scrolls up about an inch. and the link goes to something that we're not even talking about now
 
var myObject = {
	"0": "hello",
	length: 1
};
see... it's not an array
 
hi,all,what is " meta is murder" meanming?
 
4 mins ago, by Incognito
someone link me to their original convo?
 
RT @beverloo: Background images, border images and list-style images can now be animated in WebKit! http://goo.gl/5zkN3 #CSS
 
@tereško I was talking about how you told me to never put TagName("*") in a for loop and check for its length...
 
2:54 AM
Anyone find it ironic, that you can find a 3-star message by @Raynos on the right that says: 3 If you write onclick=... again ill shoot you - 1d ago by Raynos
so we didn't need to explain why it is bad after all
it is bad cos raynos will shoot you
 
o/
 
no explanation needed
 
4
Q: Where does the phrase "meta means murder" come from?

MosheWhen Meta is down, the now famous "Meta Means Murder" image is shown. Where does that phrase come from?

 
People complain when I teach by authority :\
its a pain in the ass to explain logical reason
 
@Raynos So write it in a blog post and point people to it when they ask. Code reuse! \o/
 
2:55 AM
"it is bad ! what to know why ? do your own research"
 
@YiJiang true. That is what my blog is for
 
@YiJiang it is form the blog "http://www.codinghorror.com/blog/2009/07/meta-is-murder.html"
 
the concern is real
 
@YiJiang i have been doing that with some of my SO answers
 
it's actually very ironic, that google query I linked answers why onclick in html is bad :D
 
2:57 AM
@Purmou Do you understand the previous issue of inlining your javascript events into an HTML element?
 
in the first result
 
@Incognito you mean onclick="javascript here"?
 
@Purmou Yes.
 
check it out! @Purmou... google "will I really get shot if I use onclick in html" without quotes and press I'm feeling lucky and you will see explanation
I am not making this up
 
@Incognito not really. I just don't use it there for organization. but that's how I first learned JS. I was fiddling with some JS on a wiki and was forced to do it through onclick
 

« first day (419 days earlier)      last day (4512 days later) »