These are chat archives for canjs/canjs

13th
Nov 2015
dylanrtt
@dylanrtt
Nov 13 2015 00:58
how do I access the @index of an outer loop when nesting #each blocks? ../@index doesn't work
dylanrtt
@dylanrtt
Nov 13 2015 01:11
../@index always gives the same values as @index http://jsbin.com/dapizijumo/edit?html,js,output
dylanrtt
@dylanrtt
Nov 13 2015 01:29
Also, I know the docs now say to use %index and %key but those don't seem to exist anywhere (edit: looks like justin just fixed that)
Paul Tichonczuk
@tracer99
Nov 13 2015 14:11
can you bind an event to a property change in a map using a controller?
Paul Tichonczuk
@tracer99
Nov 13 2015 14:32
Justin Meyer
@justinbmeyer
Nov 13 2015 17:56
@dylanrtt I specifically removed ../ from working with @index
b/c it cause bugs when people would use ../
@index is on a "hidden" scope
so, one way I was able to do it
{{../../list.indexOf(.)}}
works now
at least, I think it should work
though it will probably work sorta slow
it's possible I could special case ../% to allow searching in those "hidden" scopes
so this means that indexOf() won't work if you change your array with list.attr(1,"newVal")
but will if you use .push, .pop, .splice
this is a performance optimization
also, the indexOf method won't work if you have the same item twice
in your list
Justin Meyer
@justinbmeyer
Nov 13 2015 18:02
this is a performance optimization because you wouldn't want every indexOf call to bind to every "list index" in the list before it is found
that's a lot of bindings
n^2 binds
for a whole list
so if you have 100 items, there's around 5000 bindings
Mason Shin
@minsooshin
Nov 13 2015 18:05
@justinbmeyer thanks!!!
Justin Meyer
@justinbmeyer
Nov 13 2015 18:05
np
there's a new forum now too: http://forums.donejs.com/
Mason Shin
@minsooshin
Nov 13 2015 18:07
cool! thanks for letting me know
Paul Tichonczuk
@tracer99
Nov 13 2015 19:17
@justinbmeyer any help with my question above?
Mason Shin
@minsooshin
Nov 13 2015 19:18
@tracer99 if you have observable data, you can do that with curly brace on your controller
Paul Tichonczuk
@tracer99
Nov 13 2015 19:19
I understand that, but how do I reference it? {this.map} doesn't work
Mason Shin
@minsooshin
Nov 13 2015 19:19
‘{app} data’: function() {
  // event
}
it quite similar with route controller
Paul Tichonczuk
@tracer99
Nov 13 2015 19:20
what is {app} ?
Mason Shin
@minsooshin
Nov 13 2015 19:20
your data
I just give you an example
not exactly you are using since I don’t know :)
Paul Tichonczuk
@tracer99
Nov 13 2015 19:21
so I have a map assigned to a instance variable called this.map
putting in {this.map} does not work
Justin Meyer
@justinbmeyer
Nov 13 2015 19:21
@tracer99 why do you want to do this?
Mason Shin
@minsooshin
Nov 13 2015 19:22
I think it can be good reference how to use observerble data in controller
Paul Tichonczuk
@tracer99
Nov 13 2015 19:23
we have a nested controller (it's a controller that we want to re-use all over the place). being a controller, it's initialized as a child of a parenent controller. However, since it's assigned to an element ID, in the parent template, when that template gets updated (live bound change), the element gets nuked and re-drawn. So we have to re-initialize the sub controller.
of course, I'm open to a better solution
Justin Meyer
@justinbmeyer
Nov 13 2015 19:29
@tracer99 how does listening to a map relate to that?
btw, this would be a really good use for components
b/c components re-initialize themselves
I guess what you are trying to do is re-initialize the control on the same event that updated the template
so .... once nice patch might be to use a can.view.tag
that invokes your control
can.view.tag("nested-control", function(el, attrData){
  new NestedControl(el, {
    something: attrData.scope.attr('something') 
  })
})
assuming you are using mustache / stache
if you are using EJS, you can sorta do something similar
b/c you can pass functions that get passed a temporary span
Mason Shin
@minsooshin
Nov 13 2015 19:39
oh.. I didn’t know about can.view.tag
will look it up
Paul Tichonczuk
@tracer99
Nov 13 2015 20:08
@justinbmeyer thanks. I will look into and we are writing all new stuff in stache, but old stuff still in EJS
Justin Meyer
@justinbmeyer
Nov 13 2015 20:09
@tracer99 with EJS, you can have a function
that does this
Mason Shin
@minsooshin
Nov 13 2015 20:09
:) we are in transitioning from ooooooold canjs to new one. It’s big job :)
Justin Meyer
@justinbmeyer
Nov 13 2015 20:10
<%= ADD_NESTED_CONTROL %>
Paul Tichonczuk
@tracer99
Nov 13 2015 20:10
our canjs is udpated, but not all the templates
oh... that makes sense
Mason Shin
@minsooshin
Nov 13 2015 20:10
good for you @tracer99, tho
Paul Tichonczuk
@tracer99
Nov 13 2015 20:10
and that function does the work
Mason Shin
@minsooshin
Nov 13 2015 20:10
I am haivng context switching every day :)
Justin Meyer
@justinbmeyer
Nov 13 2015 20:10
ADD_NESTED_CONTROL = function(el){ new NestedControl() }
the problem is that there's no "scope" with EJS
so you can do something like:
<%= ADD_NESTED_CONTROL(arg1, arg2) %>
Paul Tichonczuk
@tracer99
Nov 13 2015 20:11
yeah, that will work based on what we are doing.
Justin Meyer
@justinbmeyer
Nov 13 2015 20:11
ADD_NESTED_CONTROL = function(arg1, arg2) {
  return function(el){
    new NestedControl(el, {op1: arg1, .. })
  }
}
Paul Tichonczuk
@tracer99
Nov 13 2015 20:12
thanks @justinbmeyer , that is exactly the solution that was eluding me. I'll chat with you next week about that FF property bug
Justin Meyer
@justinbmeyer
Nov 13 2015 20:12
sounds good
dylanrtt
@dylanrtt
Nov 13 2015 22:02
I was looking to abstract an issue with my backend where date and time are stored in a single string (and I want to edit them separately). There's a few solutions such as adding virtual fields or using a component but I was trying this http://jsbin.com/sudeqihowe/edit?html,js,console
Is this approach valid? I am having issues where the presence of another object property changes the this context of the init