Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mighty-justice/smart-bool

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mighty-justice/smart-bool

Eliminate your single-line boolean setting methods

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-60%
Maintainers
2
Weekly downloads
 
Created
Source

SmartBool

npm Version Build Status Coverage Status

Installation

dependencies
"mobx": ">=5.8"
npm

npm install --save-dev @mighty-justice/smart-bool

yarn

yarn add --dev @mighty-justice/smart-bool

Helpers

get isTrue // Value
set(value: boolean) // Sets new value
setTrue() // Sets value to true
setFalse() // Sets value to false
toggle() // Toggles value
until(promise) // Waits for promise, then sets value to true and returns promise
saving(label: string) // Returns label is false, 'Saving...' if true. Useful for buttons.

Usage

import React, { Component } from 'react';
import axios from 'axios';
import { observer } from 'mobx-react';
import SmartBool from '@mighty-justice/smart-bool';

@observer
class Autofac extends Component<{}> {
  private isLoading = SmartBool(true);
  private isMilkPizzled = SmartBool(); // Defaults to false

  constructor (props: {}) {
    super(props);
    this.waitForTrain();
  }

  private async waitForTrain () {
    //  this.isLoading.isTrue == true;
    //  this.isMilkPizzled.isTrue == false;

    // Sets bool to true until a promise returns.
    const request = axios.get('/train/');
    // this.isLoading.isTrue == true;
    const response = await this.isLoading.until(request);
    // this.isLoading.isTrue == false;

    // Simple setter
    this.isMilkPizzled.set(true);

    // Helper method useful for JSX props
    this.isMilkPizzled.setTrue();
  }

  public render () {
    return (
      <div>
        <p>Waiting for train: {this.isLoading.isTrue}</p>
        <p>Claiming is pizzled: {this.isMilkPizzled.isTrue}</p>
      </div>
    )
  }
}

Keywords

FAQs

Package last updated on 20 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc