GithubHelp home page GithubHelp logo

Add Support for UI Toolkit about unirx HOT 13 OPEN

crazyjackel avatar crazyjackel commented on July 20, 2024 4
Add Support for UI Toolkit

from unirx.

Comments (13)

scho avatar scho commented on July 20, 2024 2

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.

Kaiymu avatar Kaiymu commented on July 20, 2024

Hello @scho !

I would personally be really interested to see your code if possible, I'm also working with UITK and UniRX !

from unirx.

crazyjackel avatar crazyjackel commented on July 20, 2024

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.

Kaiymu avatar Kaiymu commented on July 20, 2024

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.

scho avatar scho commented on July 20, 2024

@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.

Kaiymu avatar Kaiymu commented on July 20, 2024

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.

crazyjackel avatar crazyjackel commented on July 20, 2024

@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.

scho avatar scho commented on July 20, 2024

@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 avatar crazyjackel commented on July 20, 2024

@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.

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.

scho avatar scho commented on July 20, 2024

@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 avatar crazyjackel commented on July 20, 2024

@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.

scho avatar scho commented on July 20, 2024

@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 avatar crazyjackel commented on July 20, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.