Coder Social home page Coder Social logo

zhuinden / service-tree Goto Github PK

View Code? Open in Web Editor NEW
33.0 3.0 5.0 18.71 MB

[ABANDONED] A tree that stores services in its node for a given key, and allows traversing them.

License: Apache License 2.0

Java 100.00%
service-tree tree service state-management

service-tree's Introduction

Service Tree

It's a tree that holds a Map<String, Object> in each of its nodes. Therefore, it allows you to store your services in it, each node identified by a particular key.

The service-tree is therefore a hierarchical service locator, independent from the Android platform.

This is a key difference to square/Mortar, which utilizes context.getSystemService() to create the hierarchy and inheritance.

You can also traverse the tree, either from top to bottom, or in reverse order from bottom to up.

Each Node is constructed with serviceTree.createNode(), and services can be bound to it using node.bindService(String, Object).

The first level is created with createRootNode(), the following levels are created by createChildNode().

Root nodes inherit root services, and child nodes inherit services from their parent node.

Creating a hierarchy

Singleton / Application

You can instantiate the ServiceTree as a singleton in a custom application class, and register root services with serviceTree.registerRootService(String, Object). These services are accessible by all root nodes, and children.

Activity

Activities are direct children of the root, so you can use serviceTree.createRootNode(String nodeTag);.

Fragment

Fragments are tricky, but they are children of the Activity. Their node can be created with serviceTree.createChildNode(Node parentNode, String childNodeTag);

Accessing services

The services you bind to a node can be accessed with node.getService(String serviceName).

While you're binding to a new node, you can also access the inherited services with node.getService(String serviceName).

Using Service Tree

In order to use Service Tree, you need to add jitpack to your project root gradle:

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

and add the compile dependency to your module level gradle.

compile 'com.github.Zhuinden:service-tree:1.6.1'

License

Copyright 2017 Gabor Varadi

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.

service-tree's People

Contributors

zhuinden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

service-tree's Issues

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.