Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLUID-6090: Provide a state tracking component #797

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

klown
Copy link
Member

@klown klown commented Jan 6, 2017

Fixed name of test html file.
Added a test to show limitation of the tracker: if the changes
occur more frequently than the polling frequency, some changes are
missed.  Also, modified the html file such that the test checkbox
is visible.
Minor cleanup of code and comments.
Changed argument name to be more in line with infusion terminology.
Added unit tests to the main test task.
Added another unit test, and did some code gardening.
Merge upstream master branch into FLUID-6090.
fluid.stateTracker.startTracking = function (that, changeEvaluator, changeListener, interval) {
var monitor = that.initMonitorInfo(changeEvaluator);
that.events.onStateChange.addListener(changeListener);
if (!!interval) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For every JavaScript value which is truthy, !! of the value is also truthy, and similarly for falsy values, so this double negation isn't necessary - https://developer.mozilla.org/en-US/docs/Glossary/Truthy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I had thought the double negative was a sanctioned Crockford-ism, but I can't recall where it's from at the moment. Certainly grunt lint didn't object ;-)

}
});

// Initiate polling.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write these comments in the JavaDoc-like style which we have standardised on in new work (lots of the core framework still lags), e.g. as seen in https://github.com/GPII/universal/blob/master/gpii/node_modules/gpii-oauth2/gpii-oauth2-authz-server/src/AuthorizationService.js#L182

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right-o.

// that has a function named evaluateChange().
// Provided by client.
// @return - the monitor object.
fluid.stateTracker.initMonitorInfo = function (changeEvaluator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A clearer pattern would have the changeEvaluator defined as an invoker on the component itself, with the initial value "fluid.notImplemented" in order to signal that the user needs to override to make the component usable - see https://issues.fluidproject.org/browse/FLUID-5733 for description

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had considered making the evaluator a function even when this code was part of the ProcessReporter. It was just easier to make it an object that contained whatever other pieces of data or functions the client wanted to stick in there. The unit tests go so far use a fluid component - see https://github.com/klown/infusion/blob/FLUID-6090/tests/component-tests/stateTracker/js/StateTrackerTests.js#L28

Another way to go is to make the state tracker component a base abstract grade with an evaluateChange invoker defined as fluid.notImplemented, as you suggest. Then, clients would derive a concrete grade and add any data/functionality they want.

Is that what you are suggesting here? A base abstract grade?


fluid.defaults("fluid.stateTracker", {
gradeNames: ["fluid.component"],
events: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component would be more usable if this field were modelised - as well as widening the contract of the "changeEvaluator" function to simply return any value which is then applied to the model. A change in that value in the opinion of the data binding system would then notify any modelListeners bound to the fie.d

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, I've made it a fluid.modelCompnent.

@amb26
Copy link
Member

amb26 commented Jan 9, 2017

Cheers, @klown, this is a great useful start on this interesting implementation. It would be helpful before we carry on to have an inventory taken of all potential users of this feature to ensure that we are meeting their needs - and to write up the results of the inventory on the JIRA. I know that both @simonbates and @colinbdclark might have potential use cases, as well as that originally found in the "Process Reporter". We will need at least 2 distinct use cases occurring in the wild in order for this component to make its way into the core framework.

Addressed some of Antranig's comments:
- removed double negative "!!".
- java-doc-ized the comments.
State tracker is now an abstract grade (fluid.stateTracker).
The State tracker is now a fluid.modelComponent.
Updated StateTracker to fluid version 3.0.0.
Modified the StateTracker to retain and handle the timer
identifier (intervalID) so that clients don't need to.  Also,
refactored the unit tests.
Call stopTracking() function when the component is destroyed to
make sure that the polling is stopped (that the interval timer is
cleared).
@klown
Copy link
Member Author

klown commented Oct 6, 2017

ok to test

Modified startTracking() to check if already tracking, and, if so, to ignore
the request and not call setInterval() an additional time.
Refactored to have a clean setup and teardown of the tracker instance.
…e tracker.

- Merge upstream master infusion branch into FLUID-6090.
- Add code to state tracker html test file to send coverage data
- Fixed typo in label element's id reference to the test checkbox
@gtirloni
Copy link
Contributor

ok to test

@idrc-cms-bot
Copy link

@CLAassistant
Copy link

CLAassistant commented Mar 9, 2020

CLA assistant check
All committers have signed the CLA.

@amb26 amb26 added the mothballed A PR that is indefinitely suspended, but not cancelled outright, and may resume label May 29, 2020
@amb26
Copy link
Member

amb26 commented May 29, 2020

Mothballed since this facility will not be developed further within the GPII but might be of further interest if the requirement arises again

@klown
Copy link
Member Author

klown commented Jun 1, 2020

Mothballing is fine. This was effectively mothballed anyway. The last time I looked, the tests were failing because they used setInterval() and/or setTimeout() to simulate changing the state of a checkbox -- time to come up with another approach, but not right now.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mothballed A PR that is indefinitely suspended, but not cancelled outright, and may resume
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants