-
Notifications
You must be signed in to change notification settings - Fork 16
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
Would it be possible to add a diagram to the readme? #11
Comments
Hello! I have started porting this project over to twinBASIC (currently in preview/beta), as in the end a MVVM framework for VBA in VBA is rather heavy, and I can't see a framework pick up any level of traction, that requires bloating one's VBA project with 125 code files before writing a single line of code! So, short-term, the VBA MVVM project is getting nuked and replaced with its twinBASIC... twin. Work done to document the many components isn't work gone to waste, because the tB version is basically the same (but with method overloading, parameterized constructors, and generics in the private implementation), but indeed my priority is to complete this port first (all while providing feedback to Wayne while tB is still beta). Mid-term, when tB is ready for it, this repo will release both x86 and x64 builds of the library (will compile to a small vbmvvm.dll file) and the source code will be split up into separate source files (tB currently only supports one single source file), and by then I'm planning to have a wiki and readme and as much documentation as possible on the framework and both its internal and public APIs. So you're a bit ahead of me here =) Feel free to submit a PR to document the current form of the project; it'll probably make a very good starting point for the twinBASIC library/project documentation. |
Just been playing around with it, this is so cool. Nice work! |
@Greedquest |
@tothzola Sorry, I didn't make one, and now I haven't looked at the framework again for a while (was waiting for the tB version) so would have to relearn it a bit to produce a diagram. I did make a fairly minimal working example which I posted on code review - I don't know whether I've used the framework perfectly idiomatically as I never received any reviews but I think a simple and pretty minimal example might help you figure things out. It was not too difficult to create by following the Rubberduck articles that Matt wrote, copying and pasting in the examples, and then just recompiling the VBA project to fix any errors of joining together the different components. Sorry that's not what you're after I know, but I'm tied up with other projects at the moment so can't pick this up just now I'm afraid. Hope the additional code review example helps illustrate the mvvm technique in practice. |
Thanks @Greedquest for your replay, thought you hade made something, no problem if not. The MVVM technique in practice, I do have some understanding, I also made a simple example based from the descriptions from here the project and also from the website. I find that @retailcoder is a great explainer 🥇, I really like his articles, would love to read something new. I know that tB is here and find it great but for now I cant use it so it remains the good old VBA. :) I would also like to have a working framework and not as a library, so I started to adapt it to my needs. What I find difficult to understand is when things get complex lets say we have a View and many controls on different frames, Found this explanation on the website but without an example don't really understand it.
Especially this part: @retailcoder can you please detail how you would implement this? I would appreciate it, thanks. |
In WPF/XAML, each UI element inherits a The property might look something like this in the ViewModel: private string _description;
public string Description
{
get { return _description; }
set
{
if (_description != value)
{
_description = value;
OnPropertyChanged(nameof(Description));
}
}
} Where So the idea was to replicate this mechanism and make it work in classic-VB - obviously without fancypants XAML markup or an elaborate object/inheritance hierarchy, but it seemed to me (still does) nothing in VBA/VB6 inherently makes MVVM completely impossible. Not without challenges (the impossibility for an abstract interface to expose a When the UI is a simple form, you write a single ViewModel class and use it as your But sometimes you need a more complex UI and the ViewModel class begins to get really crowded... with properties that can often easily be bunched into groups of closely related things... and be pulled into a "child" ViewModel class to tidy things up (Single Responsibility Principle 😉). In such cases the ViewModel exposes a get-only property that bindings can use to refer to the "child" VM, and so the binding path accordingly looks like private readonly ChildViewModel _child;
public ChildViewModel Child
{
get { return _child; }
} So that's why property binding paths get evaluated (recursively) the way they are, but then the child VM needs to fire property change notifications... and we want our VBA MVVM code to register a single VM per View/form, but then with how the MVVM infrastructure does it, that makes the "parent" ViewModel the only What this means is that the "child" view model classes should expose a Private WithEvents ChildVM As ChildViewModel
Private Sub OnPropertyChanged(ByVal PropertyName As String)
This.Notifier.OnPropertyChanged Me, PropertyName
End Sub
Private Sub Class_Initialize()
Set This.Notifier = New PropertyChangeNotifierBase
End Sub
Private Sub INotifyPropertyChanged_OnPropertyChanged(ByVal Source As Object, ByVal PropertyName As String)
This.Notifier.OnPropertyChanged Source, PropertyName
End Sub
Private Sub INotifyPropertyChanged_RegisterHandler(ByVal Handler As IHandlePropertyChanged)
This.Notifier.RegisterHandler Handler
End Sub
Private Sub ChildVM_PropertyChanged(ByVal Name As String)
This.Notifier.OnPropertyChanged ChildVM, PropertyName
End Sub The child VM can then use standard VB events to propagate changes into the MVVM binding and command managers: Public Event PropertyChanged(ByVal Name As String)
Private Type TViewModel
Description As String
'...
End Type
Private This As TViewModel
Public Property Get Description() As String
Description = This.Description
End Property
Public Property Let Description(ByVal Value As String)
If This.Description <> Value Then
This.Description = Value
OnPropertyChanged "Description"
End If
End Property
'...
Private Sub OnPropertyChanged(ByVal Name As String)
RaiseEvent PropertyChanged(Name)
End Sub Child view models could also propagate changes through the Eh, battery is running out, hope it helps! |
Thank you for the quick detailed reply! Oh by the way how does RubberduckVBA going when do we have a new release and do you plan some new articles on the site? Looking forward to it!! Cheers |
Hey Matt,
I've been taking a look at this - I'd really like to get to grips with how it works a little better. I've read the blog posts, had a look at the readme and codereview posts etc. and I understand the principle & motivation (I think), but the implementation with all these 100+ modules is kinda confusing me still :)
I was wondering if you'd consider adding some kind of high level block diagrams to the readme? I'd understand if it's not your top priority right now, and IIRC I read in one of your blog posts that you don't like diagrams that much, but personally I find visual aids valuable in providing an overview of how the code fits together. I'm still not fluent enough in polymorphism to just see some code and piece it together in my head.
In the past I've done things like:
...or this (please ignore the erroneous hungarian notation):
... and I've found them really useful coming back to the code months later, I hope reviewers have found them useful too getting to grips with the code, even if they are quite informal (well you could easily confirm/deny the reviewer perspective;).
So IDK how you'd feel about adding this/ whether you would have the time at all, but I think different people learn differently and although the blog posts are excellent for explaining concepts precisely and with clear examples, for large projects where you might want a zoomed out view, I find supplementing the code with visual aids is really helpful, although that's just my opinion.
P.s. I would consider adding this myself if you like the sound of it, and will at some point in the future if you don't do it yourself, but I thought I'd ask in advance as you're probably much better placed to make it and of course this way I could benefit too.
The text was updated successfully, but these errors were encountered: