Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Working with Observables and computes

$
0
0
Hi,

I have 1 main control and 3 other child controls. Main control is widget control and the other 3 are for select lists (with dependency):
- First Select list to select area course
- Second select list to select year (course dependent)
- Third select list  to select discipline (course and year dependent).

(our choice was to have 3 controls has we don´t know if in the future their behaviour will be different).

Now regarding to Observes and computes i have defined in widget control:

     this.options.obsSelectLists = can.Observe({course : -1, courseyear: -1, discipline: -1});
     this.options.obsSelectLists.course = new can.compute(-1);
     this.options.obsSelectLists.courseyear = new can.compute(-1);
     this.options.obsSelectLists.discipline = new can.compute(-1);

 And this is passed to controls select lists as:
            new this.options.control.selectCourses('#courses',{
              ...
              model: this.options.models.Course,
              course: this.options.obsSelectLists.course,
             ...

            }
           
            new this.options.control.selectCourseYears('#courseyears',{
              ...
              model: this.options.models.CourseYear,
              course: this.options.obsSelectLists.course,
              courseyear: this.options.obsSelectLists.courseyear,
             ...

            }   
           
            new this.options.control.selectCourseYears('#disciplines',{
              ...
              model: this.options.models.Discipline,
              course: this.options.obsSelectLists.course,
              courseyear: this.options.obsSelectLists.courseyear,
              discipline: this.options.obsSelectLists.discipline,
              ...

            }   
           
           
This 3 controls will listen for this computes and act accordingly.
For example:
    selectCourseYears control will update his compute when select element changes:
        ...
        select change": function(...){
            newval = $(this.element).find("select").val();
            this.options.courseyear(newval);
        }
        ...
       
    selectDisciplines control will see the change and then update itself:
        ....
        {courseyear} change: function(...){
            courseyear = this.options.courseyear();
            this.list.replace(this.options.model.findAll({courseyear});
        }
        ....
       
       
This works fine but i am having to many doubts of the use of Observable class, as i am not taking any advantage of using it.
Right now "this.options.obsSelectLists" could be just any object that this would not break functionality.

I guess i did not understand correctly Observable class theory and your examples.

Let me say that i am using Observables from models.List() in this 3 controls so they can update automatically.
   

If possible please provide me also some kind of example with Observebles based on this 3 controls functionality.

Thanks a lot for your support.

Cheers,
Linton Fernandes


Viewing all articles
Browse latest Browse all 3491

Trending Articles