These are chat archives for canjs/canjs

1st
Jul 2016
Justin Meyer
@justinbmeyer
Jul 01 2016 00:52
@Bajix @leoj3n thanks
yeah, we're going for "brutalism".
Thomas Sieverding
@Bajix
Jul 01 2016 00:52
#magnumOpus
Justin Meyer
@justinbmeyer
Jul 01 2016 00:52
going to make it as simple site as possible
and gear it more towards "advanced" users (ie module-based docs)
we'll let DoneJS be the glamour, and CanJS be the down and dirty
Sunil George
@georgesunil81
Jul 01 2016 12:37
A quick question from a CanJS Component newbie here. I want a component to pass back values to a controller. I also want controller to detect those passed values using a listener and then execute a function inside the controller. How can I do it? Any quick example would be great.
For example, if I have <myComponent valueToComponent="{valueToComponent}" valueFromComponent1 valueFromComponent2></myComponent>
I want to detect valueFromComponent1 and valueFromComponent2 in my controller and execute a function within my controller if any of these two values change.
Thanks in advance for your help.
Justin Meyer
@justinbmeyer
Jul 01 2016 12:58
@georgesunil81 I'm not sure what you mean by "pass back". How does it "pass back"? Through an event listener?
what do you mean by controller, a can.Control?
btw, you should use the new binding syntaxes
not the old one
you can call a method when valueFromComponent1 changes like
<my-component (value-from-component-1)="someMethod()">
Sunil George
@georgesunil81
Jul 01 2016 13:06
@justinbmeyer Thanks for your inputs. I should have been more clear, but being a newbie...Yes, my controller is a can.Control. And, the component may change the value that I pass to it from my controller. I want to detect change in that value in my controller and execute a function in it.
Justin Meyer
@justinbmeyer
Jul 01 2016 13:06
well, if you two-way bind the value
Sunil George
@georgesunil81
Jul 01 2016 13:07
I am using CanJS 2.3.24, can I use new binding syntaxes with it?
Justin Meyer
@justinbmeyer
Jul 01 2016 13:07
yes
Sunil George
@georgesunil81
Jul 01 2016 13:07
Cool.
Let me look into two way bind.
Justin Meyer
@justinbmeyer
Jul 01 2016 13:07
if you use two-way binding like:
<my-component ({component-value})="control-value"/>
your control can just listen when control-value changes on itself
is control-value a property of something on the options?
this.options.map.attr("control-value")
Sunil George
@georgesunil81
Jul 01 2016 13:09
Oh, ok. Thanks Justin. What I am trying to create is a pagination component that manages pagination and returns the current page selected by the user into my controller. The controller then fetches the current page data by calling a REST API.
Justin Meyer
@justinbmeyer
Jul 01 2016 13:11
is control-value a property of something on the options?
Sunil George
@georgesunil81
Jul 01 2016 13:11
The problem is that the API response returns back the "total number of records" there is in the db. This total number of records may change anytime. My component needs to redraw the page-buttons based on what the new "total number of records" is
No, the control-value is a variable currently. I can put it in an object though.
Justin Meyer
@justinbmeyer
Jul 01 2016 13:13
have you seen the paginate example here: https://canjs.com/docs/can.Component.html#section_Examples
you should model all stateful variables in some form of observable ... good to do even in a can.Control (can.Component makes it mandatory)
Sunil George
@georgesunil81
Jul 01 2016 13:13
No, let me look at it. Does it dynamically redraw the page-buttons based on changes in the "total number of records" considering a set number of records per page?
Justin Meyer
@justinbmeyer
Jul 01 2016 13:14
it updates the page buttons to not show "next" when there are no more pages
Sunil George
@georgesunil81
Jul 01 2016 13:15
@justinbmeyer How about if the number of pages decrease? (The number of records in the database is so dynamic at my end!)
Justin Meyer
@justinbmeyer
Jul 01 2016 14:31
it's all about observables. so if count changed, that same setup would respond to it
make sure you isolate your core stateful values
and then derive everything from that
Sunil George
@georgesunil81
Jul 01 2016 14:51
@justinbmeyer Got it Justin. Thank you so much for your help. The article you provided a link to is very helpful. Thanks again.
Matthew Phillips
@matthewp
Jul 01 2016 15:24
DoneJS contributors meeting starts in 5 minutes: https://plus.google.com/events/cakr5mtqsddv80mt1ifi4hh9vm4
Gregg Roemhildt
@roemhildtg
Jul 01 2016 19:18
@georgesunil81 a little late but it might help. I wrote a paginate widget that is similar to what you were describing link