-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GoL: Replace observable properties in View with methods.
With this, the default value and the property (as state) is also moved to Model
- Loading branch information
Said Tahsin Dane
committed
Jan 10, 2018
1 parent
72db5a5
commit 82ee550
Showing
7 changed files
with
44 additions
and
39 deletions.
There are no files selected for viewing
18 changes: 14 additions & 4 deletions
18
game-of-life-multiplatform/common/src/main/kotlin/com/novoda/gol/presentation/AppModel.kt
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,18 +1,28 @@ | ||
package com.novoda.gol.presentation | ||
|
||
import com.novoda.gol.patterns.PatternEntity | ||
import kotlin.properties.Delegates.observable | ||
|
||
class AppModel { | ||
|
||
private var isIdle by observable(true) { _, _, newValue -> | ||
onSimulationStateChanged(newValue) | ||
private var boardViewState by observable(BoardViewState(true)) { _, _, newValue -> | ||
onBoardStateChanged(newValue) | ||
} | ||
|
||
var onSimulationStateChanged: (isIdle: Boolean) -> Unit by observable<(Boolean) -> Unit>({}) { _, _, newValue -> | ||
newValue(isIdle) | ||
newValue(boardViewState.isIdle) | ||
} | ||
|
||
var onBoardStateChanged: (BoardViewState) -> Unit by observable<(BoardViewState) -> Unit>({}) { _, _, newValue -> | ||
newValue(boardViewState) | ||
} | ||
|
||
fun toggleSimulation() { | ||
isIdle = isIdle.not() | ||
boardViewState = BoardViewState(isIdle = boardViewState.isIdle.not()) | ||
onSimulationStateChanged(boardViewState.isIdle) | ||
} | ||
|
||
fun selectPattern(pattern: PatternEntity) { | ||
boardViewState = boardViewState.copy(selectedPattern = pattern) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -43,4 +43,4 @@ fun RBuilder.pattern(patternEntity: PatternEntity, onPatternSelected: () -> Unit | |
} | ||
} | ||
} | ||
} | ||
} |