brianegan / scoped_model

A Widget that passes a Reactive Model to all of it's children
BSD 3-Clause "New" or "Revised" License
774 stars 76 forks source link

Cross-platform Support #27

Closed brianegan closed 5 years ago

brianegan commented 6 years ago

Hey all,

One downside to scoped_model: It cannot be used for AngularDart / Dart Web apps because Model implements the Listenable interface from Flutter.

Proposal

Split scoped_model into 3 packages:

  1. scoped_model would contain only the Model class, which implements no interfaces.
  2. scoped_model_flutter would Import the Model class and use it for the ScopedModel / ScopedModelDescendant Widgets
  3. scoped_model_angular would provide a Pipe that can be used to listen for changes to a Model class, rebuilding the appropriate component on change. e.g. {{(myModel | listen).message}}

Pros

Makes the Model class Completely independent of Flutter, and can be re-used cross-platform.

Cons

Would love to hear your thoughts @passsy, @apwilson, @chimon2000 and others! Is anyone using the Model class as a Listenable?

apwilson commented 6 years ago

I definitely use instances of Model in AnimatedBuilders often. I also use the Listenable.merge as well when I have multiple models I'm listening to.

I can see how Listenable makes Model flutter specific. I wonder, in a non flutter environment, what is the use case for a Model? You have no widget trees to pass it down. At that point isn't it only the maintainence of a set of listeners that is gained by using a Model?

On Sat, Aug 18, 2018, 7:00 AM Brian Egan notifications@github.com wrote:

Hey all,

One downside to scoped_model: It cannot be used for AngularDart / Dart Web apps because Model implements the Listenable interface from Flutter. Proposal

Split scoped_model into 3 packages:

  1. scoped_model would contain only the Model class, which implements no interfaces.
  2. scoped_model_flutter would Import the Model class and use it for the ScopedModel / ScopedModelDescendant Widgets
  3. scoped_model_angular would provide a Pipe that can be used to listen for changes to a Model class, rebuilding the appropriate component on change.

Pros

Makes the Model class Completely independent of Flutter, and can be re-used cross-platform. Cons

Not sure if folks are currently using scoped_model as a Listenable (such as with an AnimatedBuilder widget), or merging it with other Listenables via the Listenable.merge constructor.

Would love to hear your thoughts @passsy https://github.com/passsy, @apwilson https://github.com/apwilson, @chimon2000 https://github.com/chimon2000 and others! Is anyone using the Model class as a Listenable?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/brianegan/scoped_model/issues/27, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIuGk84L9E3zUPERk2I7Kmyj6BoCguqks5uSB4BgaJpZM4WClNC .

brianegan commented 6 years ago

Thanks for the feedback :)

I wonder, in a non flutter environment, what is the use case for a Model?

I thought it might be cool to support cross-platform dev with the Model class, since you could reuse a TodoListModel or UserModel for example between AngularDart and Flutter apps without needing to rewrite anything, similar to the BLoC pattern which is based on Streams.

I think of the Listenable or Model classes as "simple streams," and some folks seem to prefer them over stream-based architectures because they're easy to work with.

AngularDart apps could pass a Model around via Dependency Injection rather than an InheritedWidget, and listen to updates using the proposed listen pipe, so I think it'd be a pretty good story on that side of the fence as well.

That said, I've gotten some mixed feedback on this proposal, and not sure folks are even really interested in this feature or if folks would even use it for cross-platform coding.

I'll keep it open for now but won't make any changes, and if we get more interest I'll consider taking some more time to flesh it out!

apwilson commented 6 years ago

I can see Model not being a Listenable. It's useful but it's something that could be an class extension like ListenableModel or something that takes a Model and returns a Listenable for the animated builder case.

On Mon, Aug 20, 2018, 2:51 AM Brian Egan notifications@github.com wrote:

Thanks for the feedback :)

I wonder, in a non flutter environment, what is the use case for a Model?

I thought it might be cool to support cross-platform dev with the Model class, since you could reuse a TodoListModel or UserModel for example between AngularDart and Flutter apps without needing to rewrite anything, similar to the BLoC pattern which is based on Streams.

I think of the Listenable or Model classes as "simple streams," and some folks seem to prefer them over stream-based architectures because they're easy to work with.

AngularDart apps could pass a Model around via Dependency Injection rather than an InheritedWidget, and listen to updates using the proposed listen pipe, so I think it'd be a pretty good story on that side of the fence as well.

That said, I've gotten some mixed feedback on this proposal, and not sure folks are even really interested in this feature or if folks would even use it for cross-platform coding.

I'll keep it open for now but won't make any changes, and if we get more interest I'll consider taking some more time to flesh it out!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/brianegan/scoped_model/issues/27#issuecomment-414261261, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIuGqs7oAKEkC5a4lqlW-p7dvB9iz7Mks5uSoa6gaJpZM4WClNC .

pyrossh commented 6 years ago

It would be great if it were cross platform. Then we could try to have a common codebase for state for web and mobile. I would try scoped_model instead of the controller pattern in this app to see how well it works in this kind of scenario. https://github.com/apptreesoftware/letsvote

gimox commented 5 years ago

Scope model in angular dart can help to share more code between mobile and web. In some apps i haven t used scope-model, implementing bloc, only for share more code from platform.

brianegan commented 5 years ago

For those interested, I've got an example of how this would work here: https://github.com/brianegan/ez_listenable

I've made it a separate package for now since it's quite a big change and increases the scope of the library.

It includes an example directory of how this change would allow you to build a common library that contains all of the shared data & business logic, as well as a Flutter and Web app that make use of this library.

gimox commented 5 years ago

Very interesting....

brianegan commented 5 years ago

Hey all -- gonna close this down for now! Beyond some initial interest, doesn't feel like folks are super keen on that concept. Since i have limited time to contribute to various projects, I'm going to keep scoped model as is for now!