Hi @manuel , as my apps become more complex, I find that I’m repeating a lot for similar logics. So I’m thinking to generate those repeatitive parts. Sort of like a mini Meteor Kitchen. For each VM, I’m thinking to have one generated code (which won’t be hand touched and will regenerate as needed) + one customizable code.
So the question is, how to properly code VM to achieve that?
Idea is like:
mixin & share were my first thought but seems not quite right …
For instance, I have 10 collections, and each of them has an Edit Form, Item Summary, Item Listing etc… with their respective subscriptions.
Take Edit Form as example, each collection shall has it’s own canSubmit logic against different fields of their own. Currently I hand coded the VMs but the majority of props don’t fit the share or mixin pattern.
I don’t mean to share or reuse (mixin) but to have a proper structure to be able to generate some generic code while be able to customized in another file.
Also those 10 collections might have 10x fields in total and other methods (as props in VM) , seems no good to put them all in ViewModel.mixin / share…
I was thinking about this and you can simplify it further by moving the save button up to arrayItem. That way you get rid of the foo and bar view models…
Replacing could be done like:: ViewModel.fineOne('vm1').prop1 = function(){ ... }
Extending prop1 seems to be a general JS question. Referencing the existing prop1 in new code will cause Max stack size issue …
Since prop1 maybe already being used in template like {{prop1}}
Idea is like: ViewModel.fineOne('vm1').prop1 = function(){ // do what original prop1 does // add extra action // return something different ... }
Forgot name of the pattern but you need to grab the original function A and the second one B and wrap them in a new one C that calls A and B. You then use the load method to add C to the view model. That way A and C can have the same name.
@manuel thanks for “esa vaina” (translation - this thing) You have made our lives so much easier with this. Pure view model objects that are easily bindable and unit tested. We love it, have been using it for quite some time, and you have cut our development times significantly.
Ronen! Good to hear from you. I’m happy esta vaina is useful to you. Right now I’m working on one that uses React instead of Blaze. I’m sorry we couldn’t meet in Cabarete. Maybe next time =)
Inline styles cannot be used to target pseudo-classes or pseudo-elements. The style binding is essentially an inline style. You need to apply the style directly on the element or use a style sheet.
As for 1 method used by multiple bindings, I can’t quite put my finger on it but it rubs me the wrong way, maybe because it’s adding to the API for little benefit, or maybe because I rarely (if ever) encounter that scenario.