Git Product home page Git Product logo

tlih's Introduction

Tlih

An Experiment to build Retained Dagger Component on top of SimpleStack's GlobalServices.

Why

If you use Zhuinden's SimpleStack you know that it has an awesome feature called ScopedServices. SimpleStack is more than a navigation manager and you can also use it to create scoped services that will keep state through process death if you use its Bundleable.

GlobalServices are ScopedServices bound to an global scopes. They survive configuration change (device rotation/activity recreation) and you can use them to provide common global services to others scoped services.

For example, you can provide application as a global service without needing a lot of casts and whatever else you need to do to find the app context.

How

SimpleStack works pretty well with Dagger, Koin, Kodein (probably) if you use one of them. In my case, I almost use Dagger as it solves all my problems. But another problem came out: I need a dagger component which will outerlive Activity. What I can do to solve that? Well, I present to you SimpleStack's Scoping mechanism.

Tlih is an experiment built on top of SimpleStack's GlobalServices. Check you the test case to see more:

    @Test fun shouldActivityRetainedComponentSurviveConfigChanges() {
        var component1: ActivityRetainedComponent? = null
        var component2: ActivityRetainedComponent? = null

        rule.scenario.run {
            onActivity { activity ->
                component1 = activity.backstack.lookup<GlobalService>().component
            }

            recreate()

            onActivity { activity ->
                component2 = activity.backstack.lookup<GlobalService>().component
            }
        }

        assertThat(component2).isNotNull().isSameAs(component1)
    }

tlih's People

Contributors

lcszc avatar

Stargazers

 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.