Did a project last year and thought I understood this, now I'm questioning it and need some help

60 views
Skip to first unread message

Sean Conrad

unread,
May 10, 2017, 6:21:34 PM5/10/17
to KnockoutJS
Pretty unsure if I used to understand and now do not understand it, or if I didn't understand it and now I'm starting to... or if I didn't and still don't.

I'm building an app that lets users book appointments. 

Screen 1: Select a Location and Service Type (Options lists, button to confirm and move on)
Screen 2: Select an available Appointment time (table, button to confirm and move on)
Screen 3: Enter Name and Contact Info (text inputs, button to confirm and move on)
Screen 4: Enter verification code (texted to user, button to confirm and move on)
Screen 5: Displays confirmation code

I'm refactoring because I realized everything was in my ViewModel and unsure of what belongs in my Model and what belongs in my ViewModel. I just put selectedLocation (the item the user picks from the list) in the Model but I need it to be accessible by the View, so I did this:

self.selectedLocation = ko.computed(function(){
     read
: function() {
          return self.model.selectedLocation();
     
},
      write
: function(value){
           
self.model.selectedLocation(value);
     
}
});



Which just seems bonkers. 

Should this just be in the ViewModel? Should I have a selectedLocation variable in the Model and a currentlySelectedLocation in the ViewModel that then updates model.selectedLocation when the user confirms the Location and Service Type?

Any help would be greatly appreciated.

Ryan Leach

unread,
May 10, 2017, 8:16:12 PM5/10/17
to knock...@googlegroups.com
Is that just a function inside your model or a knockout observable? Because KO mainly concerns itself with the View and ViewModel of MVVM the Model should be largely what's already existing for your core logic / structure. Most people treat the server as the model, or have a very thin model between the server and the viewmodel.

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sean Conrad

unread,
May 11, 2017, 3:53:20 PM5/11/17
to KnockoutJS
That's a function inside the ViewModel.

Model {
   self.selectedLocation = ko.observable("foo");
}

ViewModel {
   self.selectedLocation = ko.pureComputed etc etc
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages