Comments (13)
Hey @crazyjackel,
I've developed a quite a collection of extension methods for binding observables to VisualElements.
It's nothing fancy, but it does the job well in my opinion. Would you be interested in my code?
from unirx.
Hello @scho !
I would personally be really interested to see your code if possible, I'm also working with UITK and UniRX !
from unirx.
Hello @scho !
I would personally be really interested to see your code if possible, I'm also working with UITK and UniRX !
public static IDisposable BindVisualElementCallback<TEventType>(this VisualElement element, ReactiveCommand<TEventType> command, TrickleDown trickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase<TEventType> { var callback = new EventCallback<TEventType>((ev) => command.Execute(ev)); element.RegisterCallback(callback, trickleDown); return Disposable.Create(() => { element.UnregisterCallback(callback, trickleDown); }); }
I am trying with something like this for right now. The Idea is that I can bind to Reactive Commands.
https://github.com/crazyjackel/redmoon-reactiveKit
I am still working on this and there is a little bit of testing, but it works with Unity's Package Manager, so that's nice. (Though, Unity's Package Manager really needs some work, can't even update git packages (planned for 2021.2))
from unirx.
Thank you very much, I'm going to test it right now !
At the moment I'm trying to extend the already existing element, for exemple the Button click and be able to Subscribe to it just like in UniRX with the current UGUI
from unirx.
@Kaiymu:
Sorry for answering back so late.
I finally managed to extracted my binding extensions and put them into a gist:
https://gist.github.com/scho/6ec3f30653119b3856b1a9edfd5b0b7b
from unirx.
No problem at all ! And thank you for that, I'm looking into your implementation right now ;).
Maybe you can do a merge request ?
from unirx.
@Kaiymu: Sorry for answering back so late. I finally managed to extracted my binding extensions and put them into a gist: https://gist.github.com/scho/6ec3f30653119b3856b1a9edfd5b0b7b
I like some of these, but I have some general critiques on impl.
Bind Display should have IObservable over IObservable to support future DisplayStyles, such as Grid being added. Also saves on a calculation.
I think ClickEvents should pass the event in as an action to implement.
Seeing someone else's implementation suggests some better ways to do mine.
from unirx.
@crazyjackel:
Sure, the implementation could be improved. It's written to fit out project best and it does not claim to be a general solution for everyone.
Regarding the click events:
We never need the actual event and it allows us to do the following:
_confirmButton.Bind(viewModel.Confirm).AddTo(this);
Regarding BindDisplay:
Sure, this is not future proof. Maybe just naming it BindDisplayFlex
would make it clear, that it's either Flex
or None
.
@Kaiymu:
I'm not sure if it's wort to do a pull request. The last release of UniRx is from July 2019. If this changes, I can create a pull request.
from unirx.
@crazyjackel: Sure, the implementation could be improved. It's written to fit out project best and it does not claim to be a general solution for everyone.
Regarding the click events: We never need the actual event and it allows us to do the following:
_confirmButton.Bind(viewModel.Confirm).AddTo(this);Regarding BindDisplay: Sure, this is not future proof. Maybe just naming it
BindDisplayFlex
would make it clear, that it's eitherFlex
orNone
.@Kaiymu: I'm not sure if it's wort to do a pull request. The last release of UniRx is from July 2019. If this changes, I can create a pull request.
I am updating my implementation package for Unity with some of the concepts that you provided. I think having this as a separate package would be good instead of further bloating out this package. That is one thing I dislike about UniRX is that it is rather bloated.
from unirx.
@crazyjackel:
Sounds like a sensible decision to have a dedicated packe for the extensions.
Do you plan to publish it on the asset store or here on Github?
from unirx.
@crazyjackel: Sounds like a sensible decision to have a dedicated packe for the extensions. Do you plan to publish it on the asset store or here on Github?
https://github.com/crazyjackel/redmoon-reactiveKit
I have been developing this, I have updated the development branch recently. Provided is a Sample. Feel free to try it out and submit issues. (Besides the Extensions, I also am including a MVVM-type system and a dependency (thought, I might make it a soft-dependency) for my Dependency Injection Package)
My Binding Extensions Implementation:
https://github.com/crazyjackel/redmoon-reactiveKit/blob/main/Runtime/Scripts/BindingExtensions.cs
New Development Implementation
https://github.com/crazyjackel/redmoon-reactiveKit/blob/develop/Runtime/Scripts/BindingExtensions.cs
from unirx.
@crazyjackel:
The MVVM looks interesting, it's a bit similar to what we use, but our's is rather basic (see https://gist.github.com/scho/d737ec33aa3b5b1e7fc8e04990d866d2).
Any reason why not using Zenject for DI?
from unirx.
@crazyjackel: The MVVM looks interesting, it's a bit similar to what we use, but our's is rather basic (see https://gist.github.com/scho/d737ec33aa3b5b1e7fc8e04990d866d2).
Any reason why not using Zenject for DI?
Itβs less of dependency injection and more of a way for a class to get references to enabling and disabling managers classes. Probably main reason is that I was not aware of it or how to use it.
I like how simple your view is, but I like to keep the view and the functionality of the view model separate (also as a way to have separate loading times). The code mostly comes from when I did some WPF work with ReactiveUI (copy what seems to work to a new system.)
from unirx.
Related Issues (20)
- Extension method in UniRx.ObservableExtensions conflict with System.Reactive HOT 42
- Is this library goin to be supported any more?
- ToYieldInstruction method does not catch an error
- What?
- NextFrame() skips second frame
- Awaiting to a filtered ReactiveProperty HOT 1
- What is the difference between Timer and Delay?
- ObserveOnMainThread does not propagate events from background threads to main thread
- TimeScale doesnt effect to Observable.Timer(Scheduler.MainThread)
- Bug: `InvalidOperation` does not use correct error message HOT 1
- Make repeat on error, but when other Observable method succeed
- How to convert this to a WhenAll pattern? HOT 2
- `CancellableDisposable` does not call `_cts.Dispose()` HOT 1
- Switchmap equivalent? HOT 3
- 1
- Why does ReactiveProperty call GC.SuppressFinalize(this) if it has no finalizer?
- In Unity 2021 when i upgrade UniRX to latest vesion getting issue related to observable HOT 1
- Observable from UnityWebRequest calls OnComplete although status is still InProgress HOT 1
- Is the order of Subject to events in the same frame guaranteed?
- Incorect summary of method OnBeforeRent in ObjectPool
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unirx.