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

react-services-dev

v0.1.6

Published

Dependency injection and services layer for react.js

Downloads

3

Readme

React + Services

What is React + Services?

React + Services is a thin dependency injection layer on React.js.

Why services?

  • separate your component and application state by introducing a service layer that takes care of propagating changes through your application
  • manage component dependencies in an explicit, testable way
  • there's no events and no lifecycle management - everything is done automatically for you
  • it's tiny and easy to understand - the core is less than 100 lines of code

Installation

npm install react-services

Initialization

In order not to package multiple versions of React with your application, react-services expects getReact function to be defined.

function getReact() { return React; }

Defining services

var defineService = require("react-services").defineService

Service = defineService("NameService", function() {
  return {
    name: function() {
      return "React + Services"
    }      
  };
})

Using services

Define the services consumed by a component in the subscribe field:

var services = require("react-services")

Application = services.defineComponent({
  subscribe: {
    name: "NameService#name"
  },
  render: function() {
    return `<h1>Hello {this.state.name}</h1>`
  }
})

Service = services.defineService("NameService", function() {
  return {
    name: function() {
      return "React + Services"
    }      
  };
})

Service dependencies

Services can depend on other services to produce the correct results. Any changes are automatically propagated to dependent services.

var rservices = require("react-services")

var name = "React + Services";

NameService = rservices.defineService("NameService", function() {
  return {
    name: function() {
      return name
    },
    setName: function(newName) {
      name = newName;
      NameService.update();
    }
  };
})

GreeterService = reservices.defineService("GreeterService", function(services) {
  return {
    subscribe: {
      name: "NameService#name"
    },
    greeting: function() {
      return "Hello " + services.name + "!"
    }
  }
})

Application = rservices.defineComponent({
  subscribe: {
    greeting: "GreeterService#greeting",
    setName: "NameService#setName"
  },
  setName: function(name) {
    this.state.setName(this.refs.name.getDOMNode().value)
  },
  render: function() {
    return <form>
      <h1>{this.state.greeting}</h1>
      <input ref="name" value="React + Services" onChange={this.setName} />
    </form>
  }
      
})