• Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kotlin Coroutines based MVI architecture library for Android

Vector

logo

Build and Test

Vector is an Android library to help implement the MVI architecture pattern.

It is inspired from MvRx and Roxie, but unlike them it is built completely using Kotlin Coroutines instead of RxJava. As such, it internally only uses Coroutine primitives, and has extensive support for Suspending functions.

Vector works well with Android Architecture Components. It is 100% Kotlin, and is intended for use with Kotlin only.

Building Blocks

Vector is based primarily around three classes: VectorViewModel, VectorState, and VectorFragment.

  • VectorViewModel

The Vector ViewModel class is the heart of any screen built with Vector. It is an abstract class extending the Android Architecture Components ViewModel class, and therefore survives configuration changes. It is generic on a class implementing the VectorState interface. It is also the only class which can mutate state.

It exposes the current state through a Kotlin Flow.

  • VectorState

VectorState is an interface denoting a model class representing the view's state. We recommend using Kotlin data classes to represent view state in the interest of keeping state immutable. Use the generated copy() method to create new state objects.

  • VectorFragment

Vector provides an abstract VectorFragment class extending from AndroidX's Fragment class. A VectorFragment has a convenient coroutine scope, which can be used to easily launch Coroutines from a Fragment.

Example

Here's a contrived example to show how an app written in Vector looks like.

VectorState

data class MyState(val message: String): VectorState

VectorFragment

class MyFragment: VectorFragment() {

    private val myViewModel: MyViewModel by fragmentViewModel()

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        renderState(viewModel) { state ->
            toast(state.message)
        }
    }
}

VectorViewModel

class MyViewModel(initState: MyState): VectorViewModel<MyState>(initState) {

    init {
        getMessage()
    }

    fun getMessage() = setState { 
        copy(message = "Hello, world!") 
    }
}

When the setState() function is given a state reducer, it internally enqueues it to a Kotlin Actor. The reducers passed to this actor are processed sequentially to avoid race conditions.

Documentation

The docs can be found at the project's documentation website.

Projects using Vector

  • You can find a sample app along with the library in this repository.
  • MoonShot is another project of mine. It's an app to help you keep up with SpaceX launches, and is built with Vector.

If you would like your project using Vector to be featured here, please open an Issue on the repository. I shall take a look at it and add your project to the list.

Installation Instructions

Add the Jitpack repository to your top level build.gradle file.

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

And then add the following dependency in your module's build.gradle file:

dependencies {
  implementation "com.github.haroldadmin:Vector:(latest-version)"
}

Find the latest stable release version on the Releases page.

Latest release (stable/unstable): Release

Contributing

If you like this project, or are using it in your app, consider starring the repository to show your support. Contributions from the community are very welcome.

More Repositories

1

NetworkResponseAdapter

Retrofit call adapter to model success/failed responses as sealed types
Kotlin
562
star
2

WhatTheStack

See a pretty error screen when your Android app crashes
Kotlin
245
star
3

MoonShot

A SpaceX companion app for Android
Kotlin
161
star
4

lucilla

Fast, efficient, in-memory Full Text Search for Kotlin
Kotlin
127
star
5

MovieDB

A gorgeous TMDb client for Android
Kotlin
124
star
6

functions-differ

Tool to find Firebase Functions that changed for selective redeployments
TypeScript
39
star
7

Resumade

An Android app with a minimal material design that generates a resume for you
Kotlin
32
star
8

opengraphKt

A dead simple OpenGraph tags parser for Kotlin
Kotlin
21
star
9

json-formatter

Dead simple JSON formatter for the browser (Next.js, Tailwindcss, TypeScript)
TypeScript
8
star
10

getignore

Fetch gitignore files for your projects right from the command line
Go
7
star
11

dagger-mvrx-multimodule

Demonstrates usage of Dagger and MvRx in multi module apps
Kotlin
3
star
12

pathfix

Fixes the PATH environment variable of the current process
Go
3
star
13

EpoxyCarouselBugSample

Sample project for carousel scrolling bug in Epoxy
Kotlin
2
star
14

homebrew-pps

Homebrew Tap for the pps package
Ruby
2
star
15

translate_ref_generator

A Dart build plugin to make it easier to work with translation string files
Dart
2
star
16

UsageStatsManager-Sample

An app to demonstrate the usage of the UsageStatsManager API
Java
2
star
17

homebrew-getignore

Homebrew repository for getignore
Ruby
1
star
18

spacexkmp

A Kotlin Multiplatform wrapper for the SpaceX API
Kotlin
1
star
19

translate_ref

Annotations library for Translation Reference Generator
Dart
1
star
20

CMS

Semester project for Database Management System course (CO202)
JavaScript
1
star
21

UnitTestingSample

A sample app to help me learn unit testing through Junit 5 and Spek framework
Kotlin
1
star
22

MVRx-Lite

A lightweight state management library inspired from Airbnb's amazing MvRx library
Kotlin
1
star
23

pps

A parallel port scanner, not intended for real use
Go
1
star
24

Rosewood

An Android app to create a timeline of user interactions with their device
Kotlin
1
star