npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coveops/turbo-core

v1.2.1

Published

A utility library for turbo-charged component development

Downloads

340

Readme

Coveo Turbo Core

The Coveo Turbo Core library provides common utilities to facilitate turbo-charged JSUI component development.

Disclaimer: This library was built by the community at large and is not an official Coveo JSUI Component. Use this component at your own risk.

Getting Started

  1. Install the library into your project.
npm i @coveops/turbo-core

Decorators

Component Initialization

Coveo's component registration allows for two main strategies to load a component once the scripts and markup are present on the page: Eager and Lazy.

These decorators make it simple to choose the initialization structure without requiring boilerplate code. All of the strategies fallback to component if the LazyInitialization class isn't present by importing Coveo.Lazy.js.

component

The component decorator injects the Initialization call. It is the equivalent of having the following code at the bottom of each component:

class CustomComponent extends Component {}
Initialization.registerAutoCreateComponent(CustomComponent);

To use:

Typescript:

import { component } from '@coveopos/turbo-core'

@component
export class CustomComponent extends Component {}

Vanilla Javascript:

const component = require('@coveopos/turbo-core').component;

const CustomComponent = (function(_super) {})(Component);
module.exports.CustomComponent = component(CustomComponent);

lazy

The lazy decorator injects the LazyInitialization call. It is the equivalent of having the following code at the bottom of each component:

class CustomComponent extends Component {}
LazyInitialization.registerLazyComponent(CustomComponent.ID, () => {
    Initialization.registerAutoCreateComponent(CustomComponent);
    return CustomComponent;
});

To use:

Typescript:

import { lazyComponent } from '@coveopos/turbo-core'

@lazyComponent
export class CustomComponent extends Component {}

Vanilla Javascript:

const lazyComponent = require('@coveopos/turbo-core').lazyComponent;

const CustomComponent = (function(_super) {})(Component);
module.exports.CustomComponent = lazyComponent(CustomComponent);

lazy-dependent

The lazy-dependent decorator injects the LazyInitialization call and ensures the dependent component is loaded first. It is the equivalent of having the following code at the bottom of each component:

class CustomComponent extends Component {}
LazyInitialization.registerLazyComponent(CustomComponent.ID, () => {
    return load<IComponentDefinition>(dependentComponentId).then(() => {
        Initialization.registerAutoCreateComponent(CustomComponent);
        return CustomComponent;
    });
});

The key difference in implementation, is the ID of the dependent component must be passed as an argument to the decorator.

To use:

Typescript:

import { lazyDependentComponent } from '@coveopos/turbo-core'

@lazyDependentComponent('ResultList')
export class CustomComponent extends Component {}

Vanilla Javascript:

const lazyDependentComponent = require('@coveopos/turbo-core').lazyDependentComponent;

const CustomComponent = (function(_super) {})(Component);
module.exports.CustomComponent = lazyDependentComponent('ResultList')(CustomComponent);

requires-fields

The requires-fields decorator passes a list of fields declared in the platform to the search request:

class CustomComponent extends Component {}
Initialization.registerAutoCreateComponent(CustomComponent);
Initialization.registerComponentFields(CustomComponent.ID, ['field1', 'field2']);

To use:

Typescript:

import { requiresFields } from '@coveopos/turbo-core'

@component()
@requiresFields('field1', 'field2')
export class CustomComponent extends Component {}

Vanilla Javascript:

const component = require('@coveopos/turbo-core').component;
const requiresFields = require('@coveopos/turbo-core').requiresFields;

const CustomComponent = (function(_super) {})(Component);
module.exports.CustomComponent = requiresFields('field1', 'field2')(component(CustomComponent));

Utilities

swapVar

Merges the Coveo namespace with the namespace of the component so that exported components can be instantiated from the Coveo global object. Declare it after your exports at the root index file.

To use:

Typescript:

import { swapVar } from '@coveopos/turbo-core'

swapVar(this)

Vanilla Javascript:

```javascript
const swapVar = require('@coveopos/turbo-core').swapVar;

swapVar(module.exports);

Contribute

  1. Clone the project
  2. Build the code base: npm run build
  3. Run npm pack to get a local build
  4. Copy the resulting .tgz file to a test project, and install it.