Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:10:17+00:00 2026-06-05T18:10:17+00:00

I am struggling with a problem that keeps cropping up when working with the

  • 0

I am struggling with a problem that keeps cropping up when working with the KnockoutJS framework and MVVM in general. There are times when a property on a specific item in a collection changes and because of that change, I need to affect all the other items in that same collection. In all languages and patterns, an object isn’t supposed to “know” anything about the collection it’s in, but I find myself needing to break that rule often to get certain kinds of logic to work.

I have created a contrived example of what I’m talking about to demonstrate the hacky sort of way I’ve been solving this problem. I’m hoping someone with more experience can weigh in and show me the better way to do this.

JSFiddle Contrived Example

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:10:19+00:00Added an answer on June 5, 2026 at 6:10 pm

    I don’t know whether this is the "recommended" approach, but I will offer my advice of how I would tackle this issue. I am not a MVVM expert (though I’ve written quite a few KnockoutJS apps), but I think some OOP principles will be more than enough to help here.

    So first let’s discuss the current state of things…

    Your approach, as you correctly observed (knockout pun unintentional!), is not ideal – the Person objects are aware not just of their siblings (even if indirectly via a subscription) but also the parent object to which they are subscribing – Your Person type is subscribed to changes on the parent. Not only does this make your Person object unusable outside of this scenario, it also gives each instance too much responsibility (violating the Single Responsibility Principle) and each instance is subscribed to changes on every other instance, which is of course wasteful!

    So what’s the solution?

    To me the ideal place to put this kind of logic is on your parent object (i.e. your view model). Your view model already has knowledge of it’s child objects, so why not put the functionality there? This would make your Person type reusable elsewhere (OK so it has observables, so it’s tied to KO at the moment, but this can be overcome with the Mapping plugin) and relieves it of the responsibility of managing its siblings.

    But still this means that you have tight coupling between parent and child – not what we want in OOP! To overcome this, you can adopt a pub/sub (observer) pattern and have your Person type publish a message whenever something changes, then you can let a subscriber (e.g. you view model) decide how to respond to this event. You need not necessarily use knockout’s pub/sub offerings either, any pub/sub implementation will do. Though you may as well take advantage of what KO offers, so I would point you in the direction of these extensions/helpers to ease things a little: http://www.knockmeout.net/2012/05/using-ko-native-pubsub.html

    Hope I’ve been of help 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very annoying problem that I've been struggling with for a few
I am struggling with a very basic regex problem in my .htaccess file that
I've been struggling with this problem.. There is a wrapper div and it contains
I have a problem that I have been struggling with for a few days
I have an interesting problem that I'm struggling to fit in MapReduce. I have
Hello all you math whizzes out there! I am struggling with a math problem
Currently struggling with a problem that I've encountered variations on in the past. At
I am struggling with a problem that In my application Im having audio files
We are struggling with a problem that is driving me insane. Using this code...
I'm new to Hibernate and I'm struggling with problem: I have 3 tables and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.