Code Monkey home page Code Monkey logo

pacemaker's Introduction

Pacemaker (iOS & Android) [KMP]

Build

Run together! A running companion monitoring the heart rate of a group of people doing sports together.

Supports

  • External Bluetooth (LE) heart rate monitors (tested with Polar H10)
  • iPhone <-> iPhone connections (No internet necessary, BLE)
  • Android <-> Android connections (No internet necessary, BLE)
  • iPhone <-> Android connections (No internet necessary, BLE)

Planned

WatchOS support (via UWB chip and Internet)

Screenshots

Screenshot iOS Screenshot iOS Screenshot iOS

Install

Technical Details

Kotlin Multiplatform

This application is built as a Test/Dogfooding project for Kotlin/Multiplatform, Compose and JetBrains Fleet.

Architecture

No! ViewModels!: This project uses 'State Actors' instead.

The State Actor pattern used in 'Pacemaker' can be defined by two high level concepts:

Events

Every component in the application can emit any kind of event, including intents. Example: Some UI button that emits an event to the application

@Composable
fun MyButton() {
    Button(
        onClick = Launching { LoginIntent.emit() }
    ) {
        // ...
    }
}

State Producers

States can be produced and observed. Lets look at the producing site first:
Lets take the classic login example:

data class LoginState(val email: String, val password: String, val isLoggedIn: Boolean) : State {
    companion object Key : State.Key<LoginState> {
        val default get() = LoginState(email = "", password = "", isLoggedIn = false)
    }
}

fun CoroutineScope.launchLoginStateActor() = launchStateProducer(LoginState) {
    var state = LoginState.default

    collectEventsAsync<EmailChangedEvent> {
        state = state.copy(email = it.email)
        state.emit()
    }

    collectEventsAsync<PasswordChangedEvent> {
        state = state.copy(password = it.password)
        state.emit()
    }

    collectEventsAsync<LoginIntent> {
        val isLoggedIn = attemptLogin(state.email, state.password)
        state = state.copy(isLoggedIn = isLoggedIn)
        state.emit()
    }
}

Such states can then be used in the Application UI/Frontend easily

@Composable
fun MyLoginScreen() {
    val loginState by LoginState.collectAsState()
    MyLoginScreen(
        email = loginState.email,
        password = loginState.password
    )
}

@Composable
fun MyLoginScreen(
    email: String,
    password: String
) {
    Text(email)
    Text(password)
    Button(
        onClick = Launching { LoginIntent.emit() }
    ) {
        Text("Login")
    }
}

Libraries used

  • kotlinx.coroutines
  • kotlinx.datetime
  • SQLDelight
  • Multiplatform Settings
  • Okio

pacemaker's People

Contributors

sellmair avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pacemaker's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.