Periodic action
No edit summary
No edit summary
Line 1: Line 1:
A periodic action is a viewmodel action that runs automatically over and over again until the Disabled expression is True.
A periodic action is a ViewModel action that runs automatically over and over again until the Disabled expression is True.


In the viewmodel editor;
In the ViewModel editor:
[[File:Example of periodic action.png|none|thumb|419x419px]]
[[File:Example of periodic action.png|none|thumb|419x419px]]


You typically use this for;
You typically use this for:
* Refreshing a view in [[Windows WPF client|WPF]] with [[OCLOperators Refresh|selfVM.Refresh]] if for example your root object is in a state that changes server side.
* Refreshing a view in [[Windows WPF client|WPF]] with [[OCLOperators Refresh|selfVM.Refresh]] if, for example, your root object is in a state that changes server side.
* [[Navigating without user interaction|Automatically navigate]] on a change in the database (for example after login when a current user has ben set)
* [[Navigating without user interaction|Automatically navigate]] on a change in the database (for example, after login when a current user has been set).
* Updating a calculated value or transient collection/association that you show on screen.
* Updating a calculated value or transient collection/association that you show on the screen.
** If you want the persisted attribute A get assigned the derived attribute B you can do so with a periodicaction that starts whenever self.A<>self.B - set the Disabled expression to self.A=self.B (this way is does NOT run when A=B, only when A<>B), in the action expression you then assign B to A with the expression self.A:=self.B. Set Interval to a number X, and the disable expression will become false when B is updated and X milliseconds after B gets a new value the action will execute, and A will now become equal to B, and then the disable expression again is true, and the action rests.
** If you want the persisted attribute A to get assigned to the derived attribute B, you can do so with a periodic action that starts whenever <code>self.A<>self.B</code>. Set the Disabled expression to <code>self.A=self.B</code> (this way it does NOT run when A=B, only when A<>B). In the action expression, you then assign B to A with the expression <code>self.A:=self.B</code>. Set Interval to a number X and the disable expression will become false when B is updated; X milliseconds after B gets a new value, the action will execute, and A will now become equal to B, and then the disable expression again is true, and the action rests.
** The periodic action is a good way to detect changes that are not easily connected to user action - if you have a user entering a value and you want to do something upon apply you can also do this with a [[Derived settable attributes|reversederived]] attribute
** The periodic action is a good way to detect changes that are not easily connected to user action. If you have a user entering a value and you want to do something upon apply, you can also do this with a [[Derived settable attributes|reversederived]] attribute.


See also [[MDrivenServer periodic server-side actions]] which is a different thing, but usually works in conjuction with viewmodel periodic actions.
See also [[MDrivenServer periodic server-side actions]] which is a different thing, but usually works in conjunction with ViewModel periodic actions.
[[Category:View Model]]
[[Category:View Model]]
[[Category:Actions]]
[[Category:Actions]]

Revision as of 06:29, 4 July 2023

A periodic action is a ViewModel action that runs automatically over and over again until the Disabled expression is True.

In the ViewModel editor:

Example of periodic action.png

You typically use this for:

  • Refreshing a view in WPF with selfVM.Refresh if, for example, your root object is in a state that changes server side.
  • Automatically navigate on a change in the database (for example, after login when a current user has been set).
  • Updating a calculated value or transient collection/association that you show on the screen.
    • If you want the persisted attribute A to get assigned to the derived attribute B, you can do so with a periodic action that starts whenever self.A<>self.B. Set the Disabled expression to self.A=self.B (this way it does NOT run when A=B, only when A<>B). In the action expression, you then assign B to A with the expression self.A:=self.B. Set Interval to a number X and the disable expression will become false when B is updated; X milliseconds after B gets a new value, the action will execute, and A will now become equal to B, and then the disable expression again is true, and the action rests.
    • The periodic action is a good way to detect changes that are not easily connected to user action. If you have a user entering a value and you want to do something upon apply, you can also do this with a reversederived attribute.

See also MDrivenServer periodic server-side actions which is a different thing, but usually works in conjunction with ViewModel periodic actions.

This page was edited 11 days ago on 05/03/2024. What links here