-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from Marvin-Brouwer/78-undo
78 undo
- Loading branch information
Showing
9 changed files
with
136 additions
and
66 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
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
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,22 +1,37 @@ | ||
import { createSignal, Accessor } from 'solid-js' | ||
import { createSignal, Accessor, createMemo } from 'solid-js' | ||
import { ScorePad, createScorePad } from './scorePad' | ||
import { ScoreApplication, applyScore } from './scoreApplicationProcessor' | ||
|
||
export type ScorePadAccessor = Accessor<Readonly<ScorePad>>; | ||
export type ScorePadModifier = (score: ScoreApplication) => (Readonly<ScorePad> | void) | ||
|
||
export type ScorePadSignal = [state: ScorePadAccessor, stateSetter: ScorePadModifier]; | ||
export type ScorePadSignal = { | ||
getScorePad: ScorePadAccessor, applyScore: ScorePadModifier, | ||
canUndoScore: Accessor<boolean>, undoScore: () => void | ||
}; | ||
|
||
export function useScorePad(): ScorePadSignal { | ||
|
||
const [getUndoState, setUndoState] = createSignal<ScorePad | undefined>(undefined) | ||
const [currentScorePad, setScorePad] = createSignal<ScorePad>(createScorePad()) | ||
|
||
function modifyScorePad(application: ScoreApplication) { | ||
setScorePad(state => { | ||
const test = applyScore(state, application) | ||
console.log('currentScore', test) | ||
return test | ||
}) | ||
setUndoState(cloneScorePad(currentScorePad())) | ||
setScorePad(state => applyScore(state, application)) | ||
} | ||
|
||
const canUndoScore = createMemo(() => getUndoState() !== undefined, getUndoState) | ||
function undoScore() { | ||
const newScore = cloneScorePad(getUndoState()!) | ||
console.log('undo', newScore) | ||
setScorePad(newScore) | ||
setUndoState(undefined) | ||
} | ||
return [currentScorePad, modifyScorePad] | ||
|
||
return { getScorePad: currentScorePad, applyScore: modifyScorePad, canUndoScore, undoScore } | ||
} | ||
|
||
function cloneScorePad(scorePad: Readonly<ScorePad>): Readonly<ScorePad> { | ||
|
||
return Object.assign({}, scorePad) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.