Git Product home page Git Product logo

android-comonadic-ui's Introduction

Android Comonadic UI

An Android application implemented in a declarative way bringing some concepts from Comonadic Declarative UIs using Ξ›rrow.

What is a Comonad?

Comonads are the dual of Monads.

A Comonad represents a Space of points. We can consider a UI as a Space of states. So we can build a UI with a Comonad as it is a Space of all possible points, and user actions are movements inside this Space. Source

For example, Store is a comonadic datatype which holds a state and a render function (lambda) for giving a visual representation of its state. We can extract() the Comonad which means giving a representation of the current point in the Space. We can also move(newState) the Comonad inside the Space.

class MainActivity : Activity() {

    var greetingComponent: Store<String, Unit> by observable(Store(initialState = "John Doe") { state ->
        user_name_textview.text = state
    }) { _, _, new -> new.extract() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        greetingComponent.extract()                                 // The textview should show "John Doe"
        greetingComponent = greetingComponent.move("A new name")    // The textview should show "A new name"
      }
}

This declarative approach is similar to other libraries and languages for frontend applications like React, Elm, Halogen, etc.

πŸ… The Future is Comonadic πŸ…

Scope

This app is a classical TODOs manager example. The core features are:

  • Showing a list of TODOs. If there are no tasks then an empty case should be shown.
  • Marking a TODO as completed. It's title should be struck through.
  • Deleting a TODO.
  • Creating new TODOs.

In the future we will add more features for showing how we can interact with the Android framework with a declarative approach.

android-comonadic-ui's People

Contributors

cotel avatar

Watchers

 avatar

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.