Skip to content

View Model: initializing data and using defaultVal #477

Description

@BrentH-Alnico

Hi Boris,

I have modified one of your test files to include prop nameChar_count...to show that the below scenario works...although I don't have a refresh method showing it's usage. I do have this implemented in my app though.

https://jsfiddle.net/alnico/25fuckt3/ LOL, jsfiddle generated the f-word in its link :-)

Property comment is not initialized by data and therefore does not update on refresh (by design).
Property nameChar_count is initialized by data AND calls method/function using this for defaultVal. This works with refresh which I need...a computed property.
Calling a standard function works of course too, but I have a case where I needed to parse an array...etc whereas using a 'method' I don't and is much cleaner and encapsulated.
So essentially nameChar_count is called via extend AND is processed via defaultVal.

I have not seen this documented anywhere (doing both of these things) and wonder if this is unconventional (not by design)...although it works?

getters: [
   {getter: "name", defaultVal: "No name"}, // Compiled name() get/set
   {getter: "nameChar_count", defaultVal: this.nameChar_count },
   ],
   extend: {
      name: myNameGetSet,                      // Override name() get/set
      comment: comment,                        // Additional get/set property, not initialized by data)
      nameChar_count: function() {
         return this.name().length;
      }
   }

Thanks,
Brent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions