Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
["@babel/plugin-proposal-class-properties", { "loose": false }]
]
}
2 changes: 1 addition & 1 deletion electron.vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default defineConfig( ( { command } ) => ( {
babel: {
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-class-properties', { loose: false }],
['@babel/plugin-transform-react-jsx', { runtime: 'automatic' }],
],
},
Expand Down
2 changes: 1 addition & 1 deletion jest/babelTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = babelJest.default.createTransformer( {
],
plugins: [
[ '@babel/plugin-proposal-decorators', { legacy: true } ],
[ '@babel/plugin-proposal-class-properties', { loose: true } ],
[ '@babel/plugin-proposal-class-properties', { loose: false } ],
[ '@babel/plugin-transform-react-jsx', { runtime: 'automatic' } ],
],
} );
4 changes: 4 additions & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function withBridgeEvents( next ) {
if ( typeof next.getVersion !== 'function' ) {
next.getVersion = () => Promise.resolve();
}
// The output panel checks the output name; MobX 6 re-renders it inside the render test when this rejects.
if ( typeof next.checkOutput !== 'function' ) {
next.checkOutput = () => Promise.resolve( { ok: true, resultFilenames: [] } );
}
// Config construction reads and may write dark mode.
if ( typeof next.getDarkMode !== 'function' ) {
next.getDarkMode = () => Promise.resolve( false );
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@
"allotment": "^1.20.6",
"classnames": "^2.3.2",
"clean-stack": "3.0.1",
"computed-async-mobx": "^4.2.0",
"d3-array": "^3.2.5",
"electron-log": "^4.4.8",
"electron-store": "^8.1.0",
"electron-updater": "^5.2.4",
"filenamify": "^4.3.0",
"lodash": "^4.18.1",
"mobx": "^5.15.7",
"mobx-react-lite": "^2.2.2",
"mobx-utils": "^5.6.2",
"mobx": "^6.16.0",
"mobx-react-lite": "^4.1.0",
"mobx-utils": "^6.1.0",
"parse-filepath": "^1.0.2",
"patch-package": "^8.0.1",
"postinstall-postinstall": "^2.1.0",
Expand Down
59 changes: 59 additions & 0 deletions src/app/promisedComputed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { computed, makeObservable, _getGlobalState } from 'mobx';
import { fromPromise, isPromiseBasedObservable } from 'mobx-utils';

const ok = ( value ) => ( { ok: true, value } );
const failed = ( error ) => ( { ok: false, error } );

// Replaces computed-async-mobx: its 7.0 build mixes decorators with annotations, which MobX 6 rejects.
// Like a computed that unwraps a promise: `init` until the first resolve, then the latest resolved value.
// `get` must run inside a reaction; `busy` is true while the promise is pending.
class PromisedComputed {
constructor( init, fetch ) {
this.fetch = fetch;
this.cached = ok( init );
makeObservable( this, {
currentState: computed,
busy: computed,
value: computed,
} );
}

get currentState() {
try {
const promiseOrValue = this.fetch();
return typeof promiseOrValue?.then === 'function'
? fromPromise( promiseOrValue.then( ok, failed ) )
: ok( promiseOrValue );
} catch ( err ) {
return failed( err );
}
}

get busy() {
const state = this.currentState;
return isPromiseBasedObservable( state ) && state.state === 'pending';
}

get value() {
const state = this.currentState;
const result = !isPromiseBasedObservable( state )
? state
: state.state === 'fulfilled'
? state.value
: this.cached;
this.cached = result;
if ( result.ok ) {
return result.value;
}
throw result.error;
}

get() {
if ( !_getGlobalState().trackingDerivation ) {
throw new Error( 'promisedComputed must be used inside reactions' );
}
return this.value;
}
}

export const promisedComputed = ( init, fetch ) => new PromisedComputed( init, fetch );
15 changes: 8 additions & 7 deletions src/app/store/Alignment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, computed, action, runInAction } from 'mobx';
import { observable, computed, action, runInAction, makeObservable } from 'mobx';

import * as raxmlSettings from '../../settings/raxml';
import * as raxmlNgSettings from '../../settings/raxmlng';
Expand All @@ -23,6 +23,7 @@ const raxmlNgModelOptions = raxmlNgSettings.modelOptions;
class Alignment extends InputFile {
constructor( run, path ) {
super( run, path );
makeObservable( this );
this.substitutionModel = new RaxmlNgAlignmentSubstitutionModel( this );
this.multistateNumber = new MultistateNumber( this );
this.ngStationaryFrequencies = new RaxmlNgModelF( this );
Expand Down Expand Up @@ -379,12 +380,12 @@ class Alignment extends InputFile {
};

@action
dispose = () => {
this.unlisten();
if ( this.modeltestLoading ) {
this.cancelModelTest();
}
};
dispose() {
this.unlisten();
if ( this.modeltestLoading ) {
this.cancelModelTest();
}
}

@action
remove = () => {
Expand Down
10 changes: 7 additions & 3 deletions src/app/store/AlignmentOptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed } from 'mobx';
import { computed, makeObservable, override } from 'mobx';

import Option from './Option';
import * as raxmlNgSettings from '../../settings/raxmlng';
Expand All @@ -8,6 +8,7 @@ const raxmlNgModelOptions = raxmlNgSettings.modelOptions;
class RaxmlNgAlignmentSubstitutionModel extends Option {
constructor( alignment ) {
super( alignment.run, '', 'Substitution model' );
makeObservable( this );
this.alignment = alignment;
}
@computed get options() {
Expand Down Expand Up @@ -37,6 +38,7 @@ class RaxmlNgModelExtraParam extends Option {
super( alignment.run, addNone
? '<none>'
: options[0].value, label );
makeObservable( this );
this.alignment = alignment;
this.optionsSource = addNone
? [{ value: '<none>', title: 'none' }, ...options]
Expand Down Expand Up @@ -106,8 +108,9 @@ class RaxmlNgModelASC extends RaxmlNgModelExtraParam {
].map( ( { value, label: title } ) => ( { value, title } ) ),
{ addNone: false },
);
makeObservable( this );
}
@computed get notAvailable() {
@override get notAvailable() {
return (
!this.run.haveAlignments ||
!this.run.usesRaxmlNg ||
Expand All @@ -119,6 +122,7 @@ class RaxmlNgModelASC extends RaxmlNgModelExtraParam {
class MultistateNumber extends Option {
constructor( alignment ) {
super( alignment.run, '', 'Number of states' );
makeObservable( this );
this.alignment = alignment;
this.placeholder = 'Integer';
}
Expand All @@ -128,7 +132,7 @@ class MultistateNumber extends Option {
!this.alignment.run.usesRaxmlNg
);
}
@computed get error() {
@override get error() {
return !this.value || !Number.isInteger( Number( this.value ) );
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/store/AppStore.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { observable, action } from 'mobx';
import { observable, action, makeObservable } from 'mobx';
import StoreBase from './StoreBase';
import Citation from './Citation';
import Config from './Config';

class AppStore extends StoreBase {
constructor() {
super();
makeObservable( this );
}
citation = new Citation();
config = new Config();

Expand Down
6 changes: 5 additions & 1 deletion src/app/store/AstralTree.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { action } from 'mobx';
import { action, makeObservable } from 'mobx';

import InputFile from './InputFile';

class AstralTree extends InputFile {
constructor( ...args ) {
super( ...args );
makeObservable( this );
}
@action
remove = () => {
this.run.removeAstralTree();
Expand Down
5 changes: 4 additions & 1 deletion src/app/store/Citation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { observable, action, computed } from 'mobx';
import { observable, action, computed, makeObservable } from 'mobx';

export default class Citation {
constructor() {
makeObservable( this );
}
@observable visible = false;

formats = [
Expand Down
3 changes: 2 additions & 1 deletion src/app/store/Config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { observable, action, runInAction } from 'mobx';
import { observable, action, runInAction, makeObservable } from 'mobx';
import StoreBase, { runEvents } from './StoreBase';

export default class Config extends StoreBase {
constructor() {
super();
makeObservable( this );
this.listen();
const { rendererBridge } = /** @type {any} */ ( window );
rendererBridge.getDarkMode().then( ( value ) => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/store/FinalAlignment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, computed, action } from 'mobx';
import { observable, computed, action, makeObservable } from 'mobx';
import union from 'lodash/union';
import intersection from 'lodash/intersection';

Expand All @@ -8,6 +8,7 @@ import { join } from '../paths';

class FinalAlignment {
constructor( run ) {
makeObservable( this );
this.run = run;
this.partition = new FinalPartition( run );
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/store/FinalPartition.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { computed } from 'mobx';
import { computed, makeObservable } from 'mobx';

class FinalPartition {
constructor( run ) {
makeObservable( this );
this.run = run;
}
/*
Expand Down
3 changes: 2 additions & 1 deletion src/app/store/InputFile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, computed, action } from 'mobx';
import { observable, computed, action, makeObservable } from 'mobx';

import { base, dir, name } from '../paths';
import StoreBase from './StoreBase';
Expand All @@ -8,6 +8,7 @@ class InputFile extends StoreBase {

constructor( run, path ) {
super();
makeObservable( this );
this.run = run;
this.path = path;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/store/Option.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, computed, action } from 'mobx';
import { observable, computed, action, makeObservable } from 'mobx';
import { mixed } from 'yup';

class Option {
Expand All @@ -19,6 +19,7 @@ class Option {
hoverInfo,
{ schema = undefined, allowOnlyValidChange = false, helperText = '' } = {},
) {
makeObservable( this );
this.run = run;
this.defaultValue = defaultValue;
this.title = title;
Expand Down
9 changes: 8 additions & 1 deletion src/app/store/PartOptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed } from 'mobx';
import { computed, makeObservable } from 'mobx';
import Option from './Option';
import * as raxmlSettings from '../../settings/raxml';
import * as yup from 'yup';
Expand Down Expand Up @@ -29,6 +29,7 @@ class PartBase extends Option {
helperText,
},
);
makeObservable( this );
this.part = part;
}
@computed get alignment() {
Expand All @@ -42,6 +43,7 @@ class PartType extends PartBase {
schema: yup.string(),
allowOnlyValidChange: true,
} );
makeObservable( this );
}
@computed get finalValue() {
const { dataType, partitionType } = this.alignment;
Expand Down Expand Up @@ -71,6 +73,7 @@ class PartAAType extends PartBase {
schema: yup.string(),
allowOnlyValidChange: true,
} );
makeObservable( this );
}
options = raxmlSettings.aminoAcidSubstitutionMatrixOptions.options.map(
( value ) => ( { value, title: value } ),
Expand All @@ -85,6 +88,7 @@ class PartName extends PartBase {
schema: yup.string(), // TODO: Check that it is unique within partition
allowOnlyValidChange: true,
} );
makeObservable( this );
}
@computed get notAvailable() {
return false;
Expand All @@ -96,6 +100,7 @@ class PartStart extends PartBase {
schema: yup.number(),
allowOnlyValidChange: false,
} );
makeObservable( this );
this.disabled = true;
}
@computed get notAvailable() {
Expand All @@ -122,6 +127,7 @@ class PartEnd extends PartBase {
allowOnlyValidChange: false,
},
);
makeObservable( this );
}
@computed get min() {
return (
Expand All @@ -144,6 +150,7 @@ class PartCodon extends PartBase {
schema: yup.string(),
allowOnlyValidChange: true,
} );
makeObservable( this );
}
options = CodonModels.map( ( value ) => ( { value, title: value } ) );
@computed get notAvailable() {
Expand Down
6 changes: 4 additions & 2 deletions src/app/store/Partition.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, computed, action, reaction } from 'mobx';
import { observable, computed, action, reaction, makeObservable } from 'mobx';
import {
CODON_NONE,
CODON_SPECIFIC,
Expand Down Expand Up @@ -30,6 +30,7 @@ const getPartitionType = ( dataType, aaMatrixName = 'BLOSUM62' ) => {

class Part {
constructor( partition, { type, aaType, name, start, end, codon } ) {
makeObservable( this );
this.partition = partition;
this.type = new PartType( this, type );
this.aaType = new PartAAType( this, aaType );
Expand Down Expand Up @@ -108,6 +109,7 @@ class Part {
}
class Partition {
constructor( alignment ) {
makeObservable( this );
this.alignment = alignment;
this.defaultPartition = new Part( this, {
type: alignment.partitionType,
Expand All @@ -127,7 +129,7 @@ class Partition {
} );
reaction(
() => alignment.length,
( length, reaction ) => {
( length, _previous, reaction ) => {
reaction.dispose();
// Make default alignment complete except for mixed type
if ( this.alignment.dataType !== 'mixed' ) {
Expand Down
Loading
Loading