File tree 2 files changed +14
-5
lines changed
2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { Alg } from "../../alg" ;
2
2
import { TwistyPlayer } from "./TwistyPlayer" ;
3
+ import "../../alg/test/alg-comparison" ;
3
4
4
5
describe ( "TwistyPlayer" , ( ) => {
5
6
it ( "can be constructed" , ( ) => {
@@ -8,4 +9,14 @@ describe("TwistyPlayer", () => {
8
9
} ) ;
9
10
expect ( twistyPlayer . alg . experimentalNumUnits ( ) ) . toEqual ( 3 ) ;
10
11
} ) ;
12
+
13
+ it ( "can set alg using string" , ( ) => {
14
+ const twistyPlayer = new TwistyPlayer ( {
15
+ alg : new Alg ( "R U R'" ) ,
16
+ } ) ;
17
+ // TODO(https://github.com/microsoft/TypeScript/pull/42425): remove `@ts-ignore`.
18
+ // @ts -ignore
19
+ twistyPlayer . alg = "F2" ;
20
+ expect ( twistyPlayer . alg ) . toBeIdentical ( new Alg ( "F2" ) ) ;
21
+ } ) ;
11
22
} ) ;
Original file line number Diff line number Diff line change @@ -127,13 +127,11 @@ export class TwistyPlayer extends ManagedCustomElement {
127
127
this . #legacyExperimentalPG3DViewConfig = legacyExperimentalPG3DViewConfig ;
128
128
}
129
129
130
- set alg ( newAlg : Alg ) {
130
+ // TODO(https://github.com/microsoft/TypeScript/pull/42425): Allow setting string in the type decl.
131
+ set alg ( newAlg : Alg /* | string*/ ) {
131
132
// TODO: do validation for other algs as well.
132
133
if ( typeof newAlg === "string" ) {
133
- console . warn (
134
- "`alg` for a `TwistyPlayer` was set using a string. It should be set using a `Sequence`!" ,
135
- ) ;
136
- newAlg = new Alg ( ( newAlg as unknown ) as string ) ;
134
+ newAlg = Alg . fromString ( newAlg ) ;
137
135
}
138
136
this . #config. attributes [ "alg" ] . setValue ( newAlg ) ;
139
137
this . cursor ?. setAlg ( newAlg , this . indexerConstructor ( ) ) ; // TODO: can we ensure the cursor already exists?
You can’t perform that action at this time.
0 commit comments