These are chat archives for AvaloniaUI/Avalonia

7th
Jan 2015
Glenn Block
@glennblock
Jan 07 2015 01:35
Back to the INPC question, a real improvement would be having properties be inherently observable and have an easy way to wire things up. I forget which language I saw recently that handles observability / sync automatically for you.
I have seen while I was at MS, a pretty cool library that helped you build observable objects and without the pains of INPC. It never saw the light of day though
José Manuel Nieto
@SuperJMN
Jan 07 2015 09:00
Arghh
sounds great
bindings then would be like subscriptions
to observables
but I wonder how two-way bindings would work :smiley:
José Manuel Nieto
@SuperJMN
Jan 07 2015 13:30
by the way,
I've discovered that the WhenAnyValue (wraps a call to SubscribeToExpressionChain) from RxUI is useful to observe the changes in a path. The problem with it is that it takes a Expression in the form of viewModel => viewModel.Prop1.Prop2.Prop3
there is not way to specify it as a string like "Prop1.Prop2.Prop3", that is what the XAML Reader will read :(
I will ask Paul if it's feasible to do that. Maybe @Rohansi could help me build the expression! I usually have a hard time creating expression trees.
José Manuel Nieto
@SuperJMN
Jan 07 2015 13:47
@glennblock I've thought about the same idea: no INotifyProperty at all, but Observables. This way, a one-way binding could be just a subscription to one specific observable in the ViewModel.
@glennblock Also, I think that we need properties that are both obsevables and observers at the same time. I know that Subject<T> are like that, but I don't is it's OK to see a ViewModel with a bunch of Subject<T> properties
this way, I think that two-way bindings could be possible. What do you think, guys?
Rohan Singh
@Rohansi
Jan 07 2015 16:11
@SuperJMN what did you need help with?
turning "Prop1.Prop2.Prop3" into an expression?
José Manuel Nieto
@SuperJMN
Jan 07 2015 16:36
yes, at least to re-use the code that already exists in Reactive UI
Rohan Singh
@Rohansi
Jan 07 2015 16:36
would it know the type of viewModel
Rohan Singh
@Rohansi
Jan 07 2015 16:39
yeah but this is going to be generated from the XAML
so does it need to work with a specific viewmodel type or any?
José Manuel Nieto
@SuperJMN
Jan 07 2015 16:44
it should be a walk in the park for you, haha
from "Prop1.Prop2.Prop3" to an expression in the form vm => vm.Prop1.Prop2.Prop3
the problem could be the strong typing it requires
Rohan Singh
@Rohansi
Jan 07 2015 16:45
ye im just not sure how all of this works yet
if it knows the type of vm, its easy
José Manuel Nieto
@SuperJMN
Jan 07 2015 16:46
the type if the ViewModel is dynamic by nature
you can set it to whatever
ultimately, the only think you can affirm is that it will be an object :worried:
Rohan Singh
@Rohansi
Jan 07 2015 16:47
hmm
so creating an Expression<Func<object, object>> would work?
José Manuel Nieto
@SuperJMN
Jan 07 2015 16:49
theoretically yes
under the hood, WhenAnyValue uses reflection anyways. I think it would work
Rohan Singh
@Rohansi
Jan 07 2015 16:54
so making an expression tree wouldnt actually be the best in this case, its just required for RxUI
José Manuel Nieto
@SuperJMN
Jan 07 2015 17:01
yes, it's because of that
I was doing an alternative approach that is inherently dynamic
from scratch
but I would like to estimate if any already working code might be useful for us
Rohan Singh
@Rohansi
Jan 07 2015 17:04
if theres already code that does this, but doesnt use an expression, we can use that
José Manuel Nieto
@SuperJMN
Jan 07 2015 17:04
@grokys pointed me to SubscribeToExpressionChain (this method is called by WhenAnyValue. The first calls to the latter and acts just like a wrapper)
maybe we could use that part from Avalonia (the previous project @Grokys was working on)
although I'm not sure in which state it is!
Rohan Singh
@Rohansi
Jan 07 2015 17:09
SubscribeToExpressionChain already takes an expression
José Manuel Nieto
@SuperJMN
Jan 07 2015 17:10
anyways, I like the idea of ViewModels HAVING to expose Observables/Observers
yes, it does
and that is the problem. I'm not sure it forcing it to use a property path is a good idea
Rohan Singh
@Rohansi
Jan 07 2015 17:11
well
José Manuel Nieto
@SuperJMN
Jan 07 2015 17:12
I did some ugly tricks to achieve this kind of aberration, haha. It worked, but I wasn't happy with it.
The whole ReactiveUI uses generics in some way
Rohan Singh
@Rohansi
Jan 07 2015 17:15
so something like this would be good?
it just returns an Expression that calls a lambda
making the whole thing an expression would be a waste of effort as there arent any benefits to doing it here
José Manuel Nieto
@SuperJMN
Jan 07 2015 17:18
yes, something like that
and as you say, the only benefit of converting from string to an expression is just to be able to perform the call!
Rohan Singh
@Rohansi
Jan 07 2015 17:29
is this correct?
it prints "Rohan"
it should be ok, just needs proper error handling
José Manuel Nieto
@SuperJMN
Jan 07 2015 18:34
I'll try it when I'm back home 😃 thanks
After the call to your method it will be necessary to user reflection
In order to call WhenAnyValue
Steven Kirk
@grokys
Jan 07 2015 20:50
i'm not sure why you're using expressions - this is runtime behaviour, expressions are only really useful if you know the compile-time type
unless i'm missing something
is this just to interface with reactiveui?
Rohan Singh
@Rohansi
Jan 07 2015 21:07
yeah it expects an expression
Steven Kirk
@grokys
Jan 07 2015 21:32
i'm wondering if it wouldn't just be easier to deal with basic INPC then
i had hoped that there would be some code in reactiveui that accepts strings etc
as far as replacing INPC with observables, what problem does that solve?
as far as i see you'd still have to parse property paths and subscribe to a chain of objects
José Manuel Nieto
@SuperJMN
Jan 07 2015 22:08
yes, that's it
Rx UI makes it easier to deal with code since almost everything is strongly typed with generics
it's by design
and I think it's the way it should be :)
another thing is what I'm trying to do. It's the other side of the game.
I'm starting to see it more clear. Trying to re-use Rx UI for that is not a good thing.
Steven Kirk
@grokys
Jan 07 2015 23:39
but this is what i keep trying to say: strongly typed has no value to you because strongly typed only works at compile time!
using observables for VM properties will only mean that each property of the VM requires a new heap allocation
so instead of an int taking 4 bytes it will take 20 bytes for the observable plus 8 bytes for the reference on an x64 machine and require a heap allocation
oh sorry, 24 bytes for the observable on x64
Steven Kirk
@grokys
Jan 07 2015 23:45
and this will gain you absolutely zero. you still have to do everything you did before if you'd have used INPC
Steven Kirk
@grokys
Jan 07 2015 23:52
of course, observables will be created anyway for each bound property as perspex uses observables for binding
so that may be moot in most cases
but i can imagine in a large collection that is virtualized in the UI it could be important
that's not to say observables on a VM shouldn't be supported - they should
but i don't think it's fair to say all bindable VM properties need to be observables