Giter Site home page Giter Site logo

anzidcodogen's Introduction

Public observer generator

Annotation proccessor for generate public observers(KSP implementation)

KSP integration doc - https://github.com/google/ksp/blob/main/docs/quickstart.md

Supported annotation PublicSharedFlow, PublicLiveData, PublicStateFlow

Example:

image

image

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

dependencies {
     implementation 'com.github.haizerdev:anzidcodogen:1.0.0'
     ksp 'com.github.haizerdev:anzidcodogen:1.0.0'
}

Step 3. Please add the Kotlin-generated files folder to your source set. This is done via sourceSets block in your module’s build.gradle. The srcDir is the path to which the files were generated which was indicated by the kapt.kotlin.generated option. If you do not add this block, you’ll be flagged by a method not found error message in the IDE.

android {
  ...
     sourceSets {
          applicationVariants.all { variant ->
              getByName(variant.name) {
                  java.srcDirs += "${buildDir.absolutePath}/generated/ksp/${variant.name}/kotlin"
              }
          }
     }
}

Example generated container:

     @file:AnzidGenerationCode(
        value = ["Generated by Anzid company", "com.anzid.codegeneration.ksp.public_observer.PublicObserverProcessor"],
        date = "Generated date: Mon Nov 08 00:16:14 MSK 2021"
     )

     package com.example.codogen.ui.main

     import com.anzid.annotation.AnzidGenerationCode
     import androidx.lifecycle.LiveData
     import kotlinx.coroutines.flow.SharedFlow
     import kotlinx.coroutines.flow.StateFlow
     import kotlinx.coroutines.flow.asSharedFlow
     import kotlinx.coroutines.flow.asStateFlow


     /**
      * @see MainViewModel._test
     */
     @Suppress("UNCHECKED_CAST")
     val MainViewModel.test : LiveData<kotlin.String>
         get() {
             val observerPrivate = javaClass.getDeclaredField("_test")
             observerPrivate.isAccessible = true
             val observer = observerPrivate.get(this)

             return observer as LiveData<kotlin.String>
         }

     /**
      * @see MainViewModel._mutableEventInternal2
     */
     @Suppress("UNCHECKED_CAST")
     val MainViewModel.mutableEventInternal2 : LiveData<kotlin.String>
         get() {
             val observerPrivate = javaClass.getDeclaredField("_mutableEventInternal2")
             observerPrivate.isAccessible = true
             val observer = observerPrivate.get(this)

             return observer as LiveData<kotlin.String>
         }

     /**
      * @see MainViewModel._mutableNull
     */
     @Suppress("UNCHECKED_CAST")
     val MainViewModel.mutableNull : StateFlow<kotlin.collections.List<kotlin.Unit?>>
         get() {
             val observerPrivate = javaClass.getDeclaredField("_mutableNull")
             observerPrivate.isAccessible = true
             val observer = observerPrivate.get(this)

             return (observer as kotlinx.coroutines.flow.MutableStateFlow<kotlin.collections.List<kotlin.Unit?>>).asStateFlow()
         }

     /**
      * @see MainViewModel._mutableEvent
     */
     @Suppress("UNCHECKED_CAST")
     val MainViewModel.mutableEvent : SharedFlow<Unit>
         get() {
             val observerPrivate = javaClass.getDeclaredField("_mutableEvent")
             observerPrivate.isAccessible = true
             val observer = observerPrivate.get(this)

             return (observer as kotlinx.coroutines.flow.MutableSharedFlow<kotlin.Unit>).asSharedFlow()
         }

     /**
      * @see MainViewModel._mutableEventNull
     */
     @Suppress("UNCHECKED_CAST")
     internal val MainViewModel.mutableEventNull : SharedFlow<kotlin.Unit?>
         get() {
             val observerPrivate = javaClass.getDeclaredField("_mutableEventNull")
             observerPrivate.isAccessible = true
             val observer = observerPrivate.get(this)

             return (observer as kotlinx.coroutines.flow.MutableSharedFlow<kotlin.Unit?>).asSharedFlow()
         }

anzidcodogen's People

Contributors

haizerdev avatar

Stargazers

Dmitry avatar Chukwuka Eze avatar  avatar  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.