titanium-dependency-injection

WebJar for titanium-dependency-injection

License

License

MIT
Categories

Categories

Dependency Injection Application Layer Libs
GroupId

GroupId

org.webjars.bowergithub.lsspolymerelements
ArtifactId

ArtifactId

titanium-dependency-injection
Last Version

Last Version

3.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

titanium-dependency-injection
WebJar for titanium-dependency-injection
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/LssPolymerElements/titanium-dependency-injection

Download titanium-dependency-injection

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bowergithub.lsspolymerelements/titanium-dependency-injection/ -->
<dependency>
    <groupId>org.webjars.bowergithub.lsspolymerelements</groupId>
    <artifactId>titanium-dependency-injection</artifactId>
    <version>3.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bowergithub.lsspolymerelements/titanium-dependency-injection/
implementation 'org.webjars.bowergithub.lsspolymerelements:titanium-dependency-injection:3.0.6'
// https://jarcasting.com/artifacts/org.webjars.bowergithub.lsspolymerelements/titanium-dependency-injection/
implementation ("org.webjars.bowergithub.lsspolymerelements:titanium-dependency-injection:3.0.6")
'org.webjars.bowergithub.lsspolymerelements:titanium-dependency-injection:jar:3.0.6'
<dependency org="org.webjars.bowergithub.lsspolymerelements" name="titanium-dependency-injection" rev="3.0.6">
  <artifact name="titanium-dependency-injection" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bowergithub.lsspolymerelements', module='titanium-dependency-injection', version='3.0.6')
)
libraryDependencies += "org.webjars.bowergithub.lsspolymerelements" % "titanium-dependency-injection" % "3.0.6"
[org.webjars.bowergithub.lsspolymerelements/titanium-dependency-injection "3.0.6"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

titanium-dependency-injection

Build status

Published on webcomponents.org

To install use: bower install --save titanium-dependency-injection

LIVE DEMO AND API

<paper-button on-tap="provideButtonTapped">provide Example Service</paper-button>
<paper-button on-tap="requestButtonTapped">request Example Service</paper-button>
<h3>testValue:[[testValue]]</h3>
<script>
    class MyElement extends TitaniumDependencyResolverMixin(TitaniumProviderMixin(TitaniumRequesterMixin(Polymer.Element)))[TitaniumDependencyResolverMixin,TitaniumProviderMixin,TitaniumRequesterMixin],Polymer.Element){
        async provideButtonTapped() {
            this.provideInstance('exampleService', {
                favoriteMovie: 'Top Gun'
            })
        }

        async requestButtonTapped() {
            var service = await this.requestInstance('exampleService');
            this.set('testValue', service.favoriteMovie);
        }
    }
</script>

Scenario:

---app-main  <-- RESOLVER. anything provided below this (user-manager in this case) is resolved from this component
    --my-parent-component  <-- PROVIDER of user-manager.  user-manager lives in this component.
       -user-manager
       -component-a      
         -component-b
            -component-c
         -component-d
            -component-e
              -my-child-component   <-- needs access to user-manager becomes REQUESTER of user-manager
                -user-manager  
          -component-f
     --my-faq
     --my-feedback

How to use:

In this example we have a single instance component that is called user-manager that we would like to use in a child component nested deep in our app. Rather then binding the user-manager through the component tree in our app, we can simply provide, store, and then request the user-manager as seen below.

1. Declare a parent component as the dependency resolver, which will store the references to provided objects (user-manager)

class MyParentComponent extends  TitaniumDependencyResolverMixin(Polymer.Element) {

}

2. Provide your component in any child component

class FirstChildComponent extends TitaniumProviderMixin(Polymer.Element) {
    ready() {
        super.ready();    
        this.provideInstance("UserManager", this.$.userManager);
    }
}

3. Request your component from any child component

class DemoRequester extends TitaniumRequesterMixin(Polymer.Element) {
    async connectedCallback() {
         super.connectedCallback();
         var userManager = await this.requestInstance('UserManager');
         userManager.ensureLoggedIn();
    }
}

Be both a requester and provider

class MyComponent extends TitaniumProviderMixin(TitaniumRequesterMixin(Polymer.Element)) {
   ready() {
        super.ready();    
        this.provideInstance("MyComponent", this);
   }
   
   async connectedCallback() {
        super.connectedCallback();
        let userManager = await this.requestInstance("UserManager");
        userManager.ensureLoggedIn();
   }
   
   async onLogoutButtonClick(){
        let userManager = this.requestInstance("UserManager");
        userManager.logout();
   }
}
org.webjars.bowergithub.lsspolymerelements

Titanium Elements

Sweet, useful, and simple progressive web components.

Versions

Version
3.0.6
3.0.1