[ds] Using modified_data

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[ds] Using modified_data

Justin Dennis-3
Hi -

I have a case where I'm using DS Active Row as parent to a type, and this
type does some validation before propagating a ..save().

One chuck of validation I need to perform is conditional upon just one
field changing. I.e. if only this one field is changing, bypass all
validation and just ..save() it.

Is there any access to DS active row's "modified_data" I see in the source?
Is that safe for me to use to test if the modified_data is of size 1 and
its only element is the one element that can be changed without validation?

Hope this make some sense. Trying to avoid posting a bunch of custom code
that really isn't all that special for this conceptual issue.

Thanks for your time and help.

- Justin

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: [ds] Using modified_data

Ke Carlton-3
Yes, you can just address .modified_data directly.

DS tracks any internal changes to an object here prior to writing them to
the datasource (if ever). It will also not update the datasource if nothing
has been modified (has a zero size).

You can also compare any changes prior to saving with something like this:

public save => {
with key in .modified_data->keys
do {
.find(#key) != .raw(#key) ? stdoutnl(#key + ' has been changed')
}
..save
}

.find will return modified data if present, while .raw will return the data
currently on the the row (skipping any locally modified data).

Hope that helps,

Ke



On Mon, Sep 21, 2015 at 1:29 PM Justin Dennis <[hidden email]> wrote:

> Hi -
>
> I have a case where I'm using DS Active Row as parent to a type, and this
> type does some validation before propagating a ..save().
>
> One chuck of validation I need to perform is conditional upon just one
> field changing. I.e. if only this one field is changing, bypass all
> validation and just ..save() it.
>
> Is there any access to DS active row's "modified_data" I see in the source?
> Is that safe for me to use to test if the modified_data is of size 1 and
> its only element is the one element that can be changed without validation?
>
> Hope this make some sense. Trying to avoid posting a bunch of custom code
> that really isn't all that special for this conceptual issue.
>
> Thanks for your time and help.
>
> - Justin
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>   the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: [ds] Using modified_data

Justin Dennis-3
Hi Ke & List -

This was extremely helpful and exactly what I needed.

I had to compare .find(::field)->asstring against .raw(::field)->asstring
to get the kind of comparison I was looking for, because I wanted to know
if the data was actually changing vs. being modified to the same value. I
probably don't have to use ->asstring on .raw(), but I did.

- Justin

On Sun, Sep 20, 2015 at 9:46 PM, Ke Carlton <[hidden email]> wrote:

> Yes, you can just address .modified_data directly.
>
> DS tracks any internal changes to an object here prior to writing them to
> the datasource (if ever). It will also not update the datasource if nothing
> has been modified (has a zero size).
>
> You can also compare any changes prior to saving with something like this:
>
> public save => {
> with key in .modified_data->keys
> do {
> .find(#key) != .raw(#key) ? stdoutnl(#key + ' has been changed')
> }
> ..save
> }
>
> .find will return modified data if present, while .raw will return the data
> currently on the the row (skipping any locally modified data).
>
> Hope that helps,
>
> Ke
>
>
>
> On Mon, Sep 21, 2015 at 1:29 PM Justin Dennis <[hidden email]> wrote:
>
> > Hi -
> >
> > I have a case where I'm using DS Active Row as parent to a type, and this
> > type does some validation before propagating a ..save().
> >
> > One chuck of validation I need to perform is conditional upon just one
> > field changing. I.e. if only this one field is changing, bypass all
> > validation and just ..save() it.
> >
> > Is there any access to DS active row's "modified_data" I see in the
> source?
> > Is that safe for me to use to test if the modified_data is of size 1 and
> > its only element is the one element that can be changed without
> validation?
> >
> > Hope this make some sense. Trying to avoid posting a bunch of custom code
> > that really isn't all that special for this conceptual issue.
> >
> > Thanks for your time and help.
> >
> > - Justin
> >
> > #############################################################
> >
> > This message is sent to you because you are subscribed to
> >   the mailing list Lasso [hidden email]
> > Official list archives available at http://www.lassotalk.com
> > To unsubscribe, E-mail to: <[hidden email]>
> > Send administrative queries to  <[hidden email]>
> >
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>   the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: [ds] Using modified_data

Ke Carlton-3
Yes, you also need to consider how the datasource may affect the value. ie.
decimal precision or date formatting.

But all in all it opens up lots of possibilities.

Ke


On Thu, Sep 24, 2015 at 12:08 AM Justin Dennis <[hidden email]> wrote:

> Hi Ke & List -
>
> This was extremely helpful and exactly what I needed.
>
> I had to compare .find(::field)->asstring against .raw(::field)->asstring
> to get the kind of comparison I was looking for, because I wanted to know
> if the data was actually changing vs. being modified to the same value. I
> probably don't have to use ->asstring on .raw(), but I did.
>
> - Justin
>
> On Sun, Sep 20, 2015 at 9:46 PM, Ke Carlton <[hidden email]> wrote:
>
> > Yes, you can just address .modified_data directly.
> >
> > DS tracks any internal changes to an object here prior to writing them to
> > the datasource (if ever). It will also not update the datasource if
> nothing
> > has been modified (has a zero size).
> >
> > You can also compare any changes prior to saving with something like
> this:
> >
> > public save => {
> > with key in .modified_data->keys
> > do {
> > .find(#key) != .raw(#key) ? stdoutnl(#key + ' has been changed')
> > }
> > ..save
> > }
> >
> > .find will return modified data if present, while .raw will return the
> data
> > currently on the the row (skipping any locally modified data).
> >
> > Hope that helps,
> >
> > Ke
> >
> >
> >
> > On Mon, Sep 21, 2015 at 1:29 PM Justin Dennis <[hidden email]> wrote:
> >
> > > Hi -
> > >
> > > I have a case where I'm using DS Active Row as parent to a type, and
> this
> > > type does some validation before propagating a ..save().
> > >
> > > One chuck of validation I need to perform is conditional upon just one
> > > field changing. I.e. if only this one field is changing, bypass all
> > > validation and just ..save() it.
> > >
> > > Is there any access to DS active row's "modified_data" I see in the
> > source?
> > > Is that safe for me to use to test if the modified_data is of size 1
> and
> > > its only element is the one element that can be changed without
> > validation?
> > >
> > > Hope this make some sense. Trying to avoid posting a bunch of custom
> code
> > > that really isn't all that special for this conceptual issue.
> > >
> > > Thanks for your time and help.
> > >
> > > - Justin
> > >
> > > #############################################################
> > >
> > > This message is sent to you because you are subscribed to
> > >   the mailing list Lasso [hidden email]
> > > Official list archives available at http://www.lassotalk.com
> > > To unsubscribe, E-mail to: <[hidden email]>
> > > Send administrative queries to  <[hidden email]>
> > >
> >
> > #############################################################
> >
> > This message is sent to you because you are subscribed to
> >   the mailing list Lasso [hidden email]
> > Official list archives available at http://www.lassotalk.com
> > To unsubscribe, E-mail to: <[hidden email]>
> > Send administrative queries to  <[hidden email]>
> >
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>   the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>