This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LOADING = "Loading"; | |
const FAILED = "Failed"; | |
const LOADED = "Loaded"; | |
const PLAYING = "Playing"; | |
const STOPPED = "Stopped"; | |
// or | |
enum States { | |
LOADING = "Loading", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const currentScriptState = getCurrentScriptStateSomehow(); | |
if (currentScriptState === States.LOADING) { | |
abortCurrentOperationUntilLoaded(); | |
} | |
if (currentScriptState === States.FAILED) { | |
skipScriptOperation(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* In JS, we can write bits by using prefix `0b`. | |
* In this example, bits are separated by a space just to make | |
* it simple to apply grid reading. | |
* | |
* Grid Reading means picking one column at time and reasoning only | |
* on that column. This will be helpful in the article. | |
* | |
* Please, also note that in JS, 0b numbers can use up to 32 bits (2^32 = 4294967296). | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* In grid reading, it is important to have all the bits aligned. | |
* Unaligned bits can lead to misreading and therefore to bugs. | |
* | |
* Trust me, I've shipped in production a product that had a | |
* broken feature due to a wrong bit. | |
*/ | |
enum States { | |
LOADING /***/ = 0b000000, /* Set to 0 because it is the initial state */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* In grid reading, it is important to have all the bits aligned. | |
* Unaligned bits can lead to misreading and therefore to bugs. | |
* | |
* Trust me, I've shipped in production a product that had a | |
* broken feature due to a wrong bit. | |
*/ | |
enum States { | |
LOADING /***/ = 0b0000, /* Set to 0 because it is the initial state */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum States { | |
LOADING /***/ = 0b0000, | |
FAILED /****/ = 0b0001, | |
LOADED /****/ = 0b1110, | |
PLAYING /***/ = 0b0100, | |
STOPPED /***/ = 0b1000 | |
} | |
const currentState: number = getStateSomehow(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type BaseList = ["🛹", "🚲", "🛴", "🏄"]; | |
type RepeatAsTuple< | |
Item extends string, | |
Times extends number, | |
Result extends string[] = [], | |
> = Result["length"] extends Times ? Result : RepeatAsTuple<Item, Times, [...Result, Item]>; | |
type Rebuild< | |
AmountsList extends number[], |