mbdavid / DotVue

Implement .vue file handler in .NET with server ViewModel postback
77 stars 15 forks source link

Postback property attribute #4

Closed AdrianBathurst closed 7 years ago

AdrianBathurst commented 7 years ago

A suggestion...

The [Local] property attribute is working great, again thank you for that. What I'm finding is that I mark most of the server-side properties as "local" as I only post back what is necessary.

So my suggestion is, what if it was the reverse? Make all server-side public properties "local" by default and have a property attribute called [Postback] for properties you want to post back with each request.

so this...

[Local]
public List<string> Items { get; set; } = null;
public int Counter { get; set; };

becomes...

public List<string> Items { get; set; } = null;  (definition sent to client as it currently does)
[Postback]
public int Counter { get; set; };

and this...

var copy = Object.assign({}, request.vm.$data);

// and remove local properties before send to server
request.vm.$options.local.forEach(function (key) {
    delete copy[key];
});

form.append('data', JSON.stringify(copy));

becomes...

var copy = Object.assign({}, request.vm.$data);
var postpack = [];

// add properties before send to server
request.vm.$options.postback.forEach(function (key) {
    postback[key] = copy[key];
});

form.append('data', JSON.stringify(postback));

Not a problem if you disagree as it works fine! :)

mbdavid commented 7 years ago

Hi @AdrianBathurst, that sound a bit strange for me, because in my needs I always need send all properties to server to get more concise view model in server. [Local] are a really excpeption about this, I will use only when has a list/grid items read-only.

I don't know how you image to use, but it´s not better define this in method? Some like this:

// Send all $data except properties marked as [Local]
[SendData]
public void Save()
{
}

// Do not send any $data fom client
[DoNotSendData]
public void Load(int id)
{
}

(ok, this attributes name are terrible but I didn't think any better now 😄 )

AdrianBathurst commented 7 years ago

Thinking about it some more, you are right. I will add more components to make it more modular. Then each component will have a better viwemodel and fewer local attributes.

So lets leave it as it is. Thanks again!