-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
181 additions
and
284 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
import { | ||
TypedUseSelectorHook, | ||
useStore as __useStore, | ||
useSelector as __useSelector | ||
} from 'react-redux' | ||
import type { RootState, Store } from './store' | ||
import { useDebugValue } from 'react' | ||
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector' | ||
import { RootStateSelector, store } from './store' | ||
|
||
type TypedUseStoreHook = () => Store | ||
type EqualityFn<T> = (a: T, b: T) => boolean | ||
|
||
export const useStore = __useStore as TypedUseStoreHook | ||
const refEquality: EqualityFn<unknown> = (a, b) => a === b | ||
|
||
export const useSelector: TypedUseSelectorHook<RootState> = __useSelector | ||
export const useSelector = <TSelected>( | ||
selector: RootStateSelector<TSelected>, | ||
equalityFn: EqualityFn<TSelected> = refEquality | ||
): TSelected => { | ||
const selectedState = useSyncExternalStoreWithSelector( | ||
store.subscribe, | ||
store.getState, | ||
null, | ||
selector, | ||
equalityFn | ||
) | ||
useDebugValue(selectedState) | ||
return selectedState | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,34 @@ | ||
import type { Store } from '@/app/store' | ||
import { store } from '@/app/store' | ||
import { AssembleResult, AssemblerError, assemble as assemblePure } from './core' | ||
import { setAssemblerState, setAssemblerError } from './assemblerSlice' | ||
import { setMemoryDataFrom } from '@/features/memory/memorySlice' | ||
import { resetCpuState } from '@/features/cpu/cpuSlice' | ||
import { setEditorHighlightRange, clearEditorHighlightRange } from '@/features/editor/editorSlice' | ||
import { setException } from '@/features/exception/exceptionSlice' | ||
|
||
type Assemble = (input: string) => void | ||
|
||
export const createAssemble = (store: Store): Assemble => { | ||
const assemble: Assemble = input => { | ||
let assembleResult: AssembleResult | ||
try { | ||
assembleResult = assemblePure(input) | ||
} catch (exception) { | ||
if (exception instanceof AssemblerError) { | ||
const assemblerErrorObject = exception.toPlainObject() | ||
store.dispatch(setAssemblerError(assemblerErrorObject)) | ||
store.dispatch(clearEditorHighlightRange()) | ||
} else { | ||
store.dispatch(setException(exception)) | ||
} | ||
return | ||
} | ||
const [addressToOpcodeMap, addressToStatementMap] = assembleResult | ||
store.dispatch(setAssemblerState({ source: input, addressToStatementMap })) | ||
store.dispatch(setMemoryDataFrom(addressToOpcodeMap)) | ||
store.dispatch(resetCpuState()) | ||
const firstStatement = addressToStatementMap[0] | ||
const hasStatement = firstStatement !== undefined | ||
if (hasStatement) { | ||
store.dispatch(setEditorHighlightRange(firstStatement)) | ||
} else { | ||
export const assemble = (input: string): void => { | ||
let assembleResult: AssembleResult | ||
try { | ||
assembleResult = assemblePure(input) | ||
} catch (exception) { | ||
if (exception instanceof AssemblerError) { | ||
const assemblerErrorObject = exception.toPlainObject() | ||
store.dispatch(setAssemblerError(assemblerErrorObject)) | ||
store.dispatch(clearEditorHighlightRange()) | ||
} else { | ||
store.dispatch(setException(exception)) | ||
} | ||
return | ||
} | ||
const [addressToOpcodeMap, addressToStatementMap] = assembleResult | ||
store.dispatch(setAssemblerState({ source: input, addressToStatementMap })) | ||
store.dispatch(setMemoryDataFrom(addressToOpcodeMap)) | ||
store.dispatch(resetCpuState()) | ||
const firstStatement = addressToStatementMap[0] | ||
const hasStatement = firstStatement !== undefined | ||
if (hasStatement) { | ||
store.dispatch(setEditorHighlightRange(firstStatement)) | ||
} else { | ||
store.dispatch(clearEditorHighlightRange()) | ||
} | ||
return assemble | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.