ether-observable-processor

Ether is a framework using PubSub architectures that can be used as a replacement for common model-view archtectures such as MVP/MVC/MVVM etc.

License

License

GroupId

GroupId

com.josesamuel
ArtifactId

ArtifactId

ether-observable-processor
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

ether-observable-processor
Ether is a framework using PubSub architectures that can be used as a replacement for common model-view archtectures such as MVP/MVC/MVVM etc.
Project URL

Project URL

https://github.com/josesamuel/ether/
Source Code Management

Source Code Management

https://github.com/josesamuel/ether/

Download ether-observable-processor

How to add to project

<!-- https://jarcasting.com/artifacts/com.josesamuel/ether-observable-processor/ -->
<dependency>
    <groupId>com.josesamuel</groupId>
    <artifactId>ether-observable-processor</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.josesamuel/ether-observable-processor/
implementation 'com.josesamuel:ether-observable-processor:1.0.3'
// https://jarcasting.com/artifacts/com.josesamuel/ether-observable-processor/
implementation ("com.josesamuel:ether-observable-processor:1.0.3")
'com.josesamuel:ether-observable-processor:jar:1.0.3'
<dependency org="com.josesamuel" name="ether-observable-processor" rev="1.0.3">
  <artifact name="ether-observable-processor" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.josesamuel', module='ether-observable-processor', version='1.0.3')
)
libraryDependencies += "com.josesamuel" % "ether-observable-processor" % "1.0.3"
[com.josesamuel/ether-observable-processor "1.0.3"]

Dependencies

compile (1)

Group / Artifact Type Version
com.josesamuel : ether-processor jar 1.0.3

runtime (3)

Group / Artifact Type Version
com.josesamuel : ether-observable jar 1.0.3
com.google.auto : auto-common jar 0.8
com.squareup : kotlinpoet jar 1.3.0

Project Modules

There are no modules declared in this project.

Ether

Ether is a simple PubSub architecture framework for publishing and subscribing data.

Problems that are solved using model-view architectures can be solved much easily using Ether framework using the PubSub architecture.

Why Ether?

Let us look at a common model-view architecture - MVP

MVP Pattern

MVP succeeds in separating Model and View, but Presenter is left with the responsibility of gluing this together. Presenter will be dependent on both Model and View.

As the complexity of your code grows, so is the complexity of Presenter.

But what exactly is Presenter's role? At its core, it get the data from Model and pass it to View

Imagine if you could just

  • Focus on how to produce the data -- without worrying about who consumes it or how it is send to consumer
  • Focus on how to consume the data -- without worrying about who produces it or how it is delivered

This allows you to just focus on what is important for you -- Producing the data, and consume it without worrying about how the data moves.

This is what Ether provides

With Ether the above architecture can be simplified as

MVP Pattern

Here is a comparison of how a simple problem is solved using MVP vs Ether PubSub

Using Ether

  • Define the data class, annotate it with @EtherData, specify the triggers for the data.
//Data that will be shared

@EtherData(triggerType = CityDataTrigger::class)
data class SchoolData(val schoolCount: Int, val studentCount: Int)


//Define the triggers that should produce the above data
/**Triggers to produce [SchoolData]*/
sealed class CityDataTrigger
object Austin : CityDataTrigger()
object Dallas : CityDataTrigger()
  • Produce the data
/**
 * Publisher of [SchoolData] by extending the auto generated [AbstractSchoolDataPublisher]
 *
 * A Publisher can also be created using the auto generated [SchoolDataPublisher]
 */
class SchoolDataPublisher : AbstractSchoolDataPublisher() {

    /**
     * Gets called when the trigger for [SchoolData] is sent to the [Ether]
     */
    override fun onPublisherTrigger(trigger: CityDataTrigger) {
        when (trigger) {
            Austin -> publish(SchoolData(20, 800))
            Dallas -> publish(SchoolData(45, 1900))
        }
    }
}
  • Consume the data
/**
 * Update the given school views based on the [SchoolData] received from [Ether]
 *
 * Other ways to subscribe is [Ether.subscriberOf]
 */
fun initSchoolSubscriber(schoolCount: TextView, studentCount: TextView) =

        Ether.observableOf(SchoolData::class.java)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    schoolCount.text = it.schoolCount.toString()
                    studentCount.text = it.studentCount.toString()
                }

Getting Ether

Gradle dependency

dependencies {

	//Java library
	implementation 'com.josesamuel:ether:1.0.3'
    kapt 'com.josesamuel:ether-processor:1.0.3'
   
    //If you want observable extensions (RxJava) on top of the above, use the following instead 
    implementation 'com.josesamuel:ether-observable:1.0.3'
    kapt 'com.josesamuel:ether-observable-processor:1.0.3'

}

License

Copyright 2018 Joseph Samuel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.0.3
1.0.2
1.0.1
1.0.0