sol

solitary

Isolates private implementations within classes.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

1

Maintenance

Last Commit

1yr ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.4KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

solitary

Isolates private implementations within classes.

npm downloads total npm version npm license

Ever wanted a genuinely private scope within your classes, e.g. to protect methods from being called by derived classes accidentally? This small library offers a convenient approach to isolate private implementations within classes.

Installation

Install the solitary module via

npm install solitary --save

or

yarn add solitary

Usage

The module provides a single function as default export. Here is the signature:

import solitary from 'solitary';
solitary(Class<PrivateClass>)
  => { pvt: PublicClass  => PrivateClass,
       pub: PrivateClass => PublicClass
     }

Example

An example is worth a thousand words. This illustration promotes the decorator library bindthis too. Of course, you could use solitary without it.

import solitary from 'solitary';
import bindthis from 'bindthis';
import React from 'react';

const { pvt, pub } = solitary(
  // truly private stuff
  @bindthis
  class {
    onScroll() {
      // get some property
      const someProp = pub(this).props.someProp;
      ...
      // do something with the root node
      if(this._root) {
        ...
      }
    }

    setRoot(node) {
      // store root node for later use
      this._root = node;
    }
  }
);

export default class ExampleComponent extends React.Component {
  componentDidMount() {
    window.addEventListener('scroll', pvt(this).onScroll);
  }

  componentWillUnmount() {
    window.removeEventListener('scroll', pvt(this).onScroll);
  }

  render() {
    return (<div ref={pvt(this).setRoot}>...</div>);
  }
};

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial