Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declarative binding dependencies #300

Closed
slodge opened this issue Jun 6, 2013 · 16 comments
Closed

Declarative binding dependencies #300

slodge opened this issue Jun 6, 2013 · 16 comments
Labels
t/feature Feature request type

Comments

@slodge
Copy link
Contributor

slodge commented Jun 6, 2013

We could extend INotifyPropertyChanged properties with an attribute like:

    [DependsOn("FirstName", "LastName")]
    public string FullName
    {
        get { return FirstName + " " + LastName; }
    }

The binding layer could use this to force FullName updates whenever FirstName of LastName change

@zleao
Copy link
Contributor

zleao commented Jun 6, 2013

I'm allready doing this in my implementation.
Would love to see this in the MvvmCross framework by default.
We could also use the 'DependsOn' attribute on methods and not only on properties...:

[DependsOn("FirstName")]
public void ActWhenFirstNameChanges()
{
    (...)
}

@slodge
Copy link
Contributor Author

slodge commented Jun 6, 2013

I'm allready doing this in my implementation.

If you've got any code to share/contribute, then I'm happy to consider Pulls :)

We could also use the 'DependsOn' attribute on methods and not only on properties...:

Not sure what you are asking for here - but sounds like something different - the main suggestion here is about binding views to ViewModels. Sounds like you might have some interesting ideas - if you do, please do open them as new feature requests with a bit more detail - thanks :)

@zleao
Copy link
Contributor

zleao commented Jun 6, 2013

From what I understand, the DependsOn atribute would be used to fire the RaisePropertyChanged method, when the 'dependant' properties are changed. Am I corrrect?
In that way we could also use that mechanism to invoque parameterless methods in the ViewModel.

My implementation of the DependsOn, is done at the base of my ViewModels, that inherit from MvxViewModel.

Basically, when an new viewmodel is constructed, I store info of all the properties and methods that depend on another property. I also add an handler for PropertyChanged in the ViewModel.
After that, everytime a property is changed, the dependencies are fired/invoqued.

Perhaps i'll open a new request. Because this implmentation also covers changes for collections and items inside the collections...

@slodge
Copy link
Contributor Author

slodge commented Jun 6, 2013

From what I understand, the DependsOn atribute would be used to fire the RaisePropertyChanged method, when the 'dependant' properties are changed. Am I corrrect?

That's not what I was thinking of doing....

My idea was that I would change the source binding so that it listened for more properties names here - https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/Source/MvxPropertyInfoSourceBinding.cs#L102

My implementation of the DependsOn, is done at the base of my ViewModels, that inherit from MvxViewModel.

Sounds interesting - please do either open an issue or blog about your stuff - sounds interesting and sounds like something people can do themselves without touching the core Mvx code :)

I like different ideas :) Thanks!

(one other interesting idea is that at least one person has Fody working as an AOP technique!)

@zleao
Copy link
Contributor

zleao commented Jun 6, 2013

ah ok.
Sorry about the confusion. I didnt understood at all, your idea.
But I do now :)

I'll definitely post my approach. It has some more funcionalities than the ones I've described above.

Thanks

@slodge
Copy link
Contributor Author

slodge commented Jun 7, 2013

I've thought about it and I like your approach more than mine... so I'll add an interception hook into MvxNotifyPropertyChanged where people can do anything they want and then I'll close this!

Please do blog your ideas somewhere - good stuff :)

@zleao
Copy link
Contributor

zleao commented Jun 7, 2013

Actually I'm preparing a simple project with that implementation to put it in GitHub. I'll try to finish it today. Lots of things to do at work...

Just one question: I'm a newbie in this 'sharing ideas and code throughout the internet' and I'm not quite sure where could I post something about this. In stackoverflow is a question oriented site. In GitHub it feels that is more a 'request new features' site. Where could I post something like this?

Thanks :)

@slodge
Copy link
Contributor Author

slodge commented Jun 7, 2013

I'm not sure!

Some options:

  • Talk to the team on Make Wiki publicly editable / Wiki Pull Request #252 - they are putting together a new home for documents and will hopefully have room for articles
  • Post it on a site like CodeProject
  • Post it here on GitHub as a repo with a readme - the markdown format used in ReadMe's can be very effective and posting the readme with the code is very nice
  • You can always start a new blog somewhere - tumblr, blogger, wordpress, ... even if you never post there again

@slodge
Copy link
Contributor Author

slodge commented Jun 7, 2013

As well as sites like CodeProject, GeekChamp are very friendly and happily post articles.

As long as Google can find it, it will be found :)

@zleao
Copy link
Contributor

zleao commented Jun 8, 2013

I've posted a simple example with my DependsOn implementation, in GitHub.
https://github.com/zleao/MvvmCross-PropertyChangedEventPropagation

The Readme file is still very poor on info, but tomorrow (9 of June) I will complete the file with detailed info of what I'm doing there, how can be used and my vision for future improvements in that approach.

Hope this can be usefull for someone. It has been for me :)

@slodge
Copy link
Contributor Author

slodge commented Jun 9, 2013

Thanks @zleao

Will take a look :)

I haven't had time to put together a sample yet, but following your suggestion I added a new interceptor point which will get notifications from all MvxNotifyPropertyChanged classes (this won't include ObservableCollections today - but we might implement our own ObsCollection in the future - see #257):

To create an interceptor:

I think interceptors would normally need to work using Type's rather instances - they'd probably want to cache reflected type information.

I will put together a sample at some point... but right now a bit busy!

@slodge
Copy link
Contributor Author

slodge commented Jun 9, 2013

@zleao - your sample looks good - I like it :) :) :)

I'm a bit worried about the Dispose code - as I've found it hard in the past to work out when to Dispose ViewModels :/

One thing you could maybe help is if you use WeakReference subscription methods - e.g. see https://github.com/slodge/MvvmCross/blob/v3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakSubscriptionExtensionMethods.cs#L42 - that might stop your ViewModel being held in memory by an ObservableCollection - this problem wouldn't happen in your sample, but might happen if your VM shares the ObservableCollection with some other object.

One other 'interesting' thought for you: I learned recently that if an object sends a null or string.Empty notification, then this means Everything has changed - so I had to add support for that in a few places.

@zleao
Copy link
Contributor

zleao commented Jun 9, 2013

Yep, the weakreference is the way to go. Very similar to the implementation in the messenger plugin. That is actually one of the things I'm going to write in the readme file.
Thanks :)

@zleao
Copy link
Contributor

zleao commented Jun 9, 2013

I didn't know about that Notification particularity! But just to see if I got it, when you say "everything has changed", you're referring to say, an entire viewmodel? Or just a specific property?

@slodge
Copy link
Contributor Author

slodge commented Jun 9, 2013

@slodge
Copy link
Contributor Author

slodge commented Jul 18, 2013

Between @zleao's excellent repo and the new rio code and the blog posts on Fody, this is definitely fully covered - closing

@slodge slodge closed this as completed Jul 18, 2013
martijn00 added a commit to martijn00/MvvmCross that referenced this issue Dec 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/feature Feature request type
Development

No branches or pull requests

2 participants