The Engines.DataPool object can be used to store and retrieve values that are shared by multiple Klips, such as a user name and password that are applied to more than one Klip. It also provides a way to monitor changes in the data pool, such as when a user logs in or out through one of the Klips.
For example, when two Klips require the user to login in order to access data, one can be designated the 'master' Klip responsible for the login and logout procedures, with the other Klip designated as the 'slave'. When the user logs in through the master Klip, the slave Klip is notified of the login status and reacts accordingly. On the other hand, when the user logs in through the slave Klip, it lets the master Klip know this attempt is being made, so that the master Klip can go ahead with the login process. The master Klip will then notify the slave Klip of the login status, and the slave Klip reacts accordingly.
The three functions available in the Engines.DataPool object can be used to execute the above process:
- setDataPool() can be used to store the user's username, password, and login status in the data pool
- getDataPool() can be used to retrieve the stored username, password, and login status from the data pool
- notifyPool() can be used by the master Klip to monitor for login requests from the slave Klip, or by the slave Klip to monitor for login commands from the master Klip
- User presses the "Log In" button in a slave Klip.
- Slave Klip sends a login request by setting "LOGIN" to the data pool "Login_Example_loginReq"
that the master Klip is monitoring:
Engines.DataPool.setPool("Login_Example_loginReq", "LOGIN"); - Master Klip detects the change in the "Login_Example_loginReq" pool:
Engines.DataPool.notifyPool("Login_Example_loginReq", logInOrOut);
and executes the login process by interacting with the server. - If login is successful, the master Klip puts the user's information in the data pool:
Engines.DataPool.setPool("Login_Example_username", c_username.value);
Engines.DataPool.setPool("Login_Example_password", c_password.value);
and sends a notification to the slave Klip by setting "LOGIN" to the data pool "Login_Example_loginNotify" that the slave Klip is listening for:
Engines.DataPool.setPool("Login_Example_loginNotify", "LOGIN"); - Slave Klip gets the notification through:
Engines.DataPool.notifyPool("Login_Example_loginNotify", logInOrOut);
and executes data displaying tasks.