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

@bufferapp/product-features

v1.9.20

Published

Product feature loader for buffer

Downloads

27

Readme

@bufferapp/product-features

This component Provides the logic for supported product plans and features

You can use it by importing the module and adding a <FeatureLoader> component surrounding the component you wish to show based on usecase

This is how to import the component:

import FeatureLoader from '@bufferapp/product-features';

So if you have a feature named 'super_mega_feature' and you want the <Super> component to display for those users, you would wrap the component in

<FeatureLoader supportedFeature={'super_mega_feature'}><Super /></FeatureLoader>

If you want to fallback to something else when the 'super_mega_feature' isn't available then you can provide the fallback={Component} parameter.

This should allow you to be able to send through some value if this feature isn't available, maybe showing a message saying, hey why not upgrade to enjoy this feature, or perhaps just some static text / element to hold its place in the UI

To see more of the usecases supported, check out the story.jsx file...

When we use this component we pass in productFeatures: state.productFeatures so you shouldn't pass those in as they are being provided by the redux store but you can chose to send them in if you are using the component in isolation, just like in the tests themselves

Higher Order Component

There is also a higher order component available to you that exposes some useful functions to you if you want to handle the displaying and hiding logic yourself.

This is available via

import { WithFeatureLoader } from '@bufferapp/product-features';

This component exposes a features property onto its child with a list of methods available, these are:

  • isFreeUser
    • returns a boolean
  • isProUser
    • returns a boolean
  • isSupportedPlan(testPlan)
    • accepts a single plan to test for, or an array of plans
    • returns a boolean
  • isSupportedFeature(testFeature)
    • accepts a single feature to test for, or an array of features
    • returns a boolean

You can use this in the following way:

    import { WithFeatureLoader } from '@bufferapp/product-features';
    
    // The property features gets loaded automatically from the redux state
    const TextComponent = ({ features, ...other }) => {
      if (features.isFreeUser()) {
        return (<Text {...other}>Free User</Text>);
      }
      else if (features.isProUser()) {
        return (<Text {...other}>Pro User</Text>);
      }
      
      return null;
    };

    TextComponent.propTypes = {
      features: PropTypes.any.isRequired,
    };
    
    const TextComponentWithFeatureLoader = WithFeatureLoader(TextComponent);

    // Now when you want to use it, you can just use it like any other component
    return <TextComponentWithFeatureLoader size={'large'} />;

This gives you full control of how you show data, and how you control the flow of displaying particular content, such as when you want to only display an icon for certain users, but its deeply nested inside your component, and creating a whole new component with just a small alteration would cause too much code duplication.