Skip to content
Snippets Groups Projects
Select Git revision
  • c8094786c1de111f45f8273be302375632ced654
  • main default protected
  • renovate/lock-file-maintenance
  • demo protected
  • person-select-custom
  • dbp-translation-component
  • icon-set-mapping
  • port-i18next-parser
  • remove-sentry
  • favorites-and-recent-files
  • revert-6c632dc6
  • lit2
  • advertisement
  • wc-part
  • automagic
  • publish
  • wip-cleanup
  • demo-file-handling
18 results

provider

  • Clone with SSH
  • Clone with HTTPS
  • Patrizio Bekerle's avatar
    Bekerle, Patrizio authored
    Dispatch dbp-set-property event to parent (if any) so that current element doesn't terminate event if it has the attribute set itself (#48)
    c8094786
    History

    Provider Web Components

    GitLab Repository

    You can install this component via npm:

    npm i @dbp-toolkit/provider

    Local development

    # get the source
    git clone git@gitlab.tugraz.at:dbp/web-components/toolkit.git
    cd toolkit/packages/provider
    
    # install dependencies (make sure you have npm version 4+ installed, so symlinks to the git submodules are created automatically)
    yarn install
    
    # constantly build dist/bundle.js and run a local web-server on port 8002 
    yarn run watch
    
    # run tests
    yarn test

    Jump to http://localhost:8002 and you should get a demo page.

    Provider

    Usage

    You can provide attributes (e.g. global-name) for components inside the provider:

    <provider global-name="value" global-name2="value2">
      <dbp-person-select subscribe="local-name:global-name"></dbp-person-select>
      <dbp-person-profile subscribe="local-name:global-name,local-name2:global-name2"></dbp-person-profile>
    </provider>
    <script type="module" src="node_modules/@dbp-toolkit/provider/dist/dbp-provider.js"></script>

    All other components are also inherent providers (see below), so you don't really need dbp-provider in the shadow dom of other components. The use of dbp-provider is mainly suggested being used for namespacing (e.g. different languages or entry point urls on the same page) or to deliver attribute changes across different components.

    Attributes

    • init (optional): set your vars to values
      • example <provider init="foo=bar"></provider>
    • id (optional): set an id, useful for debugging
      • example <provider id="p-1"></provider>

    AdapterLitElement

    This is a class you can derive your component class from instead of LitElement.

    You can locally "subscribe" to attributes (e.g. local-name) that can be provided by a dbp-provider (e.g. global-name). You need to make this available attributes as LitElement properties.

    Example

    Multiple attributes can be subscribed when separated by a comma (,).

    <dbp-person-select subscribe="local-name:global-name,local-name2:global-name2"></dbp-person-select>

    If local-name and global-name are the same you could also instead of local-name:local-name just write local-name:

    <dbp-person-select subscribe="local-name"></dbp-person-select>

    Inherent provider

    AdapterLitElement are themselves provider that will provide all their own attributes to all the elements in their shadow dom.

    In this example dbp-auth-keycloak would use the set-property event to propagate an auth property. dbp-person-select-demo would act as provider for auth. dbp-person-select would subscribe to auth to receive the bearer token via this.auth.token.

    <dbp-person-select-demo auth lang="de" entry-point-url="http://127.0.0.1:8000">
      <!-- #shadow-root -->
      <dbp-auth-keycloak></dbp-auth-keycloak>
      <dbp-person-select subscribe="auth" lang="${this.lang}" entry-point-url="${this.entryPointUrl}"></dbp-person-select>
    </dbp-person-select-demo>

    AdapterElement

    This is a wrapper for third party webcomponents. you can wrap this class around to support the provider functionality in third party webcomponents.

    You can locally "subscribe" to attributes (e.g. local-name) that can be provided by a dbp-provider (e.g. global-name). The dbp-adapter will set the attributes to his childnodes.

    Example

    Multiple attributes can be subscribed when separated by a comma (,).

    <provider global-name="value" global-name2="value2">
      <dbp-provider-adapter subscribe="local-name:global-name">
        <third-party-webcomponent>  </third-party-webcomponent>
      </dbp-provider-adapter>
    </provider>
    <script type="module" src="node_modules/@dbp-toolkit/provider/dist/dbp-provider.js"></script>
    <script type="module" src="node_modules/@dbp-toolkit/provider/dist/dbp-adapter.js"></script>