-
Notifications
You must be signed in to change notification settings - Fork 5
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
encapsulate the format of phetioID #41
Comments
In #25 (comment), @zepumph said: sonificationUISoundsSampled.js is client wrapper code, so we don't have access to the Tandem instance there. We only have the string literal (phetioID). |
In #25 (comment), I said:
#41 (comment): "then factor out the id-related functions so that they can be by both Tandem and cases like the above" |
In #25 (comment) @zepumph said: |
What's the barrier to having a library that encapsulates tandem id and is usable by both sims and wrappers? |
And for the record... The lack of encapsulation is not limited to wrappers. I see 9 occurrences of |
Looks like not all occurrences of '.' in the phet-io repository are related to tandem identifier. But my point is some of them likely are, and it's not easy to tell which ones. |
I see two of the 9 (10 for me) that apply to this problem: var format = function( phetioID ) {
if ( phetioID.indexOf( '.' ) > 0 ) {
var lastIndex = phetioID.lastIndexOf( '.' );
return phetioID.substring( 0, lastIndex + 1 ) + '%c' + phetioID.substring( lastIndex + 1, phetioID.length );
} These should use use a Tandem static method to parse so that we can factor out the usage of '.' into a singular "tandemDelimiterChar" in Tandem.js. Is this the type of thing you are trying to centralize? |
The delimiter is only part of the encapsulation problem. The functions for picking apart a tandem id are the other part. E.g the above example is essentially duplicating |
phetioEvents.js should change to take a Tandem as an argument rather than a phetioID. Other places I see sonification: these look like they are doing string matching and probably OK /**
* Get the display name from a lower case, dot separated string.
* @param {string} phetioID
* @returns {*}
*/
var getFriendlyName = function( phetioID ) {
var array = phetioID.split( '.' );
var tail = array[ array.length - 1 ];
return toWhitespaced( tail );
}; instance-proxies.js does prefix matching, maybe can be deleted. I'm not convinced that factoring out var array = phetioID.split( '.' );
var tail = array[ array.length - 1 ]; into an auxiliary library file that is only used from one location. In fact https://stackoverflow.com/questions/573145/get-everything-after-the-dash-in-a-string-in-javascript pointed out that a simpler implementation is |
@pixelzoom thoughts? |
Not clear what specifically you're referring to, so I can't comment on whether I think that are OK. Things are properly encapsulated if: ... and that is currently not the case. |
Related issue: phetsims/molecules-and-light#165, phetio ids should not be formed using string concatenation |
Based on the remarks in this issue and in phetsims/molecules-and-light#165 I want to make sure we are on the same page about usage of simIFrameClient.invokeSequence([
{ phetioID: 'buildAnAtom.gameScreen.model.provideFeedbackProperty', method: 'setValue', args: [ false ] },
{ phetioID: 'buildAnAtom.gameScreen.view.scoreboard.scoreText', method: 'setVisible', args: [ false ] },
{ phetioID: 'buildAnAtom.gameScreen.view.scoreboard.startOverButton', method: 'setVisible', args: [ false ] }
]); The first In order to factor out the var Tandem = require('SOME WAY OF LOADING TANDEM.JS IN A WRAPPER HTML FILE');
// ...
var tandem = Tandem.createRootTandem('buildAnAtom'); // Note: root tandem is defined for sims, not for wrappers. The wrapper could access the sim Tandem.rootTandem but it would be asynchronous
simIFrameClient.invokeSequence([
{ phetioID: tandem.createTandem('gameScreen').createTandem('model').createTandem('provideFeedbackProperty', method: 'setValue', args: [ false ] },
// ... If this is what you are picturing, then please describe how the benefits outweigh the costs. If this is not what you are picturing, then please clarify or describe an alternative. |
I'm OK with usages like:
... where you're using a complete id that was formed elsewhere. If you were forming this id using string concatenation, or somehow manipulating this id (e.g. |
To me, string manipulation and using intact phetioIDs (both in the wrapper code) use the same assumptions about id structure and separator key. @pixelzoom would you explain how you find these different? Please note that I am only talking about the wrapper side, which most often means that we aren't using requirejs, but rather plain ol' javascript. UPDATE: formatting (@samreid) |
@pixelzoom I factored out PhetioIDUtils and used it in Tandem.js and createInstanceProxyDiv.js, can you please review? |
Looks good to me. Anything else to do? |
That's all for now, closing. |
Relocating this from #25 (comment), since it's an issue of it's own. Also related to #40.
There is currently no encapsulation of the tandem id format. The separator (
'.'
) appears as a string literal in numerous places (see #40). And client code is doing things like this:If it's not appropriate to use
Tandem
in cases like the above, then factor out the id-related functions so that they can be by bothTandem
and cases like the above. With the current approach, you currently have zero encapsulation of the id format.The text was updated successfully, but these errors were encountered: