Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is observer pattern unidirectional or bidirectional data flow

Tags:

javascript

I intend to use observer pattern to update views automatically once value of model has been changed. It's obvious that a model is observable (subject) and DOM elements are observers that are staring at model for any changes so that they can update themselves.

But do you think it is still unidirectional data flow if I have a button which is observing model value and on click modify model value

like image 607
hoangfin Avatar asked Apr 15 '26 04:04

hoangfin


1 Answers

The observer pattern is unidirectional, but your use case is bidirectional, while it's extending the observer pattern implementation.


The observer pattern defines, that the subject object will notify the observer if it's updated and the observer will implement an notify() function accordingly.

What you describe isn't part of that pattern. You can implement it and if data flows it would be bidirectional. But it is not part of the pattern definition.

like image 179
johannespartin Avatar answered Apr 17 '26 17:04

johannespartin