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

Use PHET_CORE/merge instead of _.extend #71

Closed
3 tasks done
zepumph opened this issue Sep 30, 2019 · 25 comments
Closed
3 tasks done

Use PHET_CORE/merge instead of _.extend #71

zepumph opened this issue Sep 30, 2019 · 25 comments

Comments

@zepumph
Copy link
Member

zepumph commented Sep 30, 2019

This issue is to discuss and implement the conversion of our extending pattern of options from using _.extend() to merge(). At today's design pattern meeting, there were no objections towards moving to a "always use merge" pattern.

Action items:

  • Make sure all developers know about this change.
  • Update documentation to reflect this change in pattern.
  • Investigate updating previous usages to use merge instead of _.extends.
    • The first here is a blanket conversion from _.extends to require( 'PHET_CORE/merge')
    • If there aren't many problems, then we can worry about making it right.
@zepumph zepumph self-assigned this Sep 30, 2019
@zepumph
Copy link
Member Author

zepumph commented Oct 10, 2019

I posted to the dev channel:

I'm working on #71, and RE: the first checkbox, here is your PSA:
In new code, use merge instead of _.extend in call cases where you can require it.

image
👍

pixelzoom added a commit to phetsims/natural-selection that referenced this issue Oct 11, 2019
zepumph added a commit to phetsims/gravity-force-lab-basics that referenced this issue Oct 11, 2019
zepumph added a commit to phetsims/fluid-pressure-and-flow that referenced this issue Oct 11, 2019
zepumph added a commit to phetsims/resistance-in-a-wire that referenced this issue Oct 11, 2019
zepumph added a commit to phetsims/gravity-force-lab that referenced this issue Oct 11, 2019
zepumph added a commit to phetsims/coulombs-law that referenced this issue Oct 11, 2019
zepumph added a commit that referenced this issue Oct 11, 2019
zepumph added a commit to phetsims/phet-info that referenced this issue Oct 11, 2019
zepumph added a commit to phetsims/chipper that referenced this issue Oct 11, 2019
@zepumph
Copy link
Member Author

zepumph commented Oct 11, 2019

I made a way to automatically convert usages of _.extend to merge, including adding the import. It is convoluted, and probably wasn't worth the time, but I'm happy, because. . . well . . . automation.

Here are the steps to reproduce:

  1. pull all repos

  2. Make sure you have NO working copy changes in any of the repos you are touching.

  3. go to chipper/eslint/eslintrc.js and turn the no-extend rule to 2 (error).

  4. go to CHIPPER/lint.js and turn on the fix option, and uncomment the fix outputter

  5. go active-runnables or your favorite data list, and edit the repos you want this to apply to.

  6. Add the following script to a file called git/sandbox/js.js or another scrap file, just make just to change the path below. This script will add the merge require statement for each filepath in a file called test.txt.

    ( async () => {
    
       const cp = require( 'child_process' );
       const execute = require( '../perennial/js/common/execute' );
       const fs = require( 'fs' );
    
       const x = fs.readFileSync( 'test.txt', 'utf-8' ).trim().split( /\r?\n/ ).map( sim => sim.trim() );
    
       x.forEach( async file => {
    
         await new Promise( resolve => {
    
           const f = `${process.cwd()}\\${file.split( '/' ).join( '\\' )}`.split( '\\' ).join( '\\\\' );
           console.log( 'fixing', f );
    
           const s = cp.spawn( 'bash' );
           s.stdin.end( `grunt insert-require-statement --name=merge --file=${f}` );
           s.once( 'exit', () => {
             resolve();
           } );
         } );
    
       } );
       await execute( 'rm', [ 'test.txt' ], process.cwd() );
     } )();
  7. Run for-each.sh perennial/data/active-runnables "grunt lint"

  8. Run for-each.sh perennial/data/active-runnables "git diff --name-only --staged | xargs git diff --name-only > test.txt && node ../sandbox/js.js". This script is responsible for gathering a list of files that have working copy changes in them, and running grunt insert-require-statement on them to add merge (via the node script).

  9. Run aqua, and make sure all is well.

I ran this process for the sims I am responsible for, mainly as a test, and things went very well. In fact, the validation in merge fixed one spot in FPAF where we were passing a faulty arg in (see commit above in WaterTowerScreenView).

I am not recommending that anyone else do these steps, but I thought it was important to keep good notes. Likely I will try to convert other repos until we can think of a reason not too (i.e. see #73).

@zepumph
Copy link
Member Author

zepumph commented Oct 11, 2019

Also note that I added a lint rule for this purpose, which supports the "fix" option, but I don't necessarily think it should stick around.

@zepumph
Copy link
Member Author

zepumph commented Oct 11, 2019

I updated documentation in phetsims/phet-info@0d075cb and ed3bb6b
image

@pixelzoom
Copy link
Contributor

#73 is a prerequisite to global replacement of _.extend with merge.

@zepumph
Copy link
Member Author

zepumph commented Oct 11, 2019

@pixelzoom, after looking through #73, does the global replacement seem good for you?

@pixelzoom
Copy link
Contributor

yes, commented in the issue and closed it.

zepumph added a commit to phetsims/coulombs-law that referenced this issue Oct 11, 2019
@zepumph
Copy link
Member Author

zepumph commented Oct 11, 2019

In fact, the validation in merge fixed one spot in FPAF where we were passing a faulty arg in

Add one more to the bug catch count!

@pixelzoom
Copy link
Contributor

pixelzoom commented Oct 11, 2019

That indicates that there is a missing test in mergeTest.js. Should we correct that?

@zepumph
Copy link
Member Author

zepumph commented Oct 11, 2019

I do not think so. It was a faulty usage, not faulty merge code.

@pixelzoom
Copy link
Contributor

#74 is a prerequisite to global replacement of _.extend with merge.

pixelzoom added a commit to phetsims/vector-addition that referenced this issue Oct 11, 2019
@zepumph
Copy link
Member Author

zepumph commented Oct 17, 2019

I'm in the process of fixing all active runnables not already touched currently, and it is going well. The scripts above are doing their job, and I will just make sure to test well, and monitor CT this afternoon. Commits likely coming soon.

jbphet pushed a commit to phetsims/number-line-common that referenced this issue Apr 1, 2020
jbphet pushed a commit to phetsims/number-line-common that referenced this issue Apr 4, 2020
@zepumph
Copy link
Member Author

zepumph commented May 21, 2020

There is a no-extend lint rule that isn't turned on. I'm not sure how hard it would be to get this going in our post es6-modules. I'll take a look.

@zepumph zepumph self-assigned this May 21, 2020
zepumph added a commit to phetsims/chipper that referenced this issue May 21, 2020
@zepumph
Copy link
Member Author

zepumph commented May 21, 2020

This was covered by the bad-sim-text lint rule, so I deleted it.

@zepumph zepumph removed their assignment May 21, 2020
jbphet pushed a commit to phetsims/number-line-common that referenced this issue May 26, 2020
@zepumph
Copy link
Member Author

zepumph commented Jan 28, 2021

All that is left is a review on the sim-specific cases.

@jessegreenberg
Copy link
Contributor

I reviewed phetsims/capacitor-lab-basics@2493d0c and HingePointNode looks good in that sim.

Usages in ESP are also good. Closing.

jessegreenberg pushed a commit to phetsims/greenhouse-effect that referenced this issue Apr 21, 2021
samreid pushed a commit to phetsims/scenery-phet that referenced this issue Apr 9, 2022
samreid pushed a commit to phetsims/phet-info that referenced this issue Apr 23, 2022
samreid pushed a commit to phetsims/scenery-phet that referenced this issue May 16, 2022
marlitas pushed a commit to phetsims/scenery-phet that referenced this issue Jun 22, 2022
marlitas pushed a commit to phetsims/sun that referenced this issue Jun 28, 2022
zepumph added a commit to phetsims/perennial that referenced this issue Jul 21, 2022
zepumph added a commit to phetsims/perennial that referenced this issue Jul 21, 2022
zepumph added a commit to phetsims/perennial that referenced this issue Jul 21, 2022
samreid pushed a commit to phetsims/tambo that referenced this issue Oct 28, 2022
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 17, 2024
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 17, 2024
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 17, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants