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

mobservable

v1.2.5

Published

Observable data. Reactive functions. Simple code.

Downloads

361

Readme

mobservable

Observable data. Reactive functions. Simple code.

Build Status Coverage Status Join the chat at https://gitter.im/mweststrate/mobservable #mobservable channel on reactiflux discord

Introduction

Mobservable enables your data structures to become observable. Next to that it can make your functions (or React components) reactive, so that they re-evaluate whenever relevant data is altered. It's like Excel for JavaScript: any data structure can be turned into a 'data cell', and every function or user interface component can be turned into a 'formula' that updates automatically. Mobservable is unopiniated about which data structures to use; it can work with mutable objects, arrays, (cyclic) references, classes etc. So that your actions, stores and user interface can remain KISS. Besides that, it is fast.

The essentials

Mobservable can be summarized in two functions that will fundamentally simplify the way you write React applications. Let's start by building a really really simple timer application:

var timerData = mobservable.observable({
  secondsPassed: 0
});

setInterval(function() {
  timerData.secondsPassed++;
}, 1000);

var Timer = mobservable.observer(React.createClass({
  render: function() {
    return (<span>Seconds passed: { this.props.timerData.secondsPassed } </span> )
  }
}));

React.render(<Timer timerData={timerData} />, document.body);

In the example above the timerData data structure is made observable and the Timer component is turned into an observer. Mobservable will automatically track all relations between observable data and observing functions (or components) so that the minimum amount of observers is updated to keep all observers fresh.

Its as simple as that. In the example above the Timer will automatically update each time the property timerData.secondsPassed is altered. This is because setter notifies the Timer observer. The actual interesting thing about this approach are the things that are not in the code:

  • The setInterval method didn't alter. It still treats timerData as a plain JS object.
  • If the Timer component would be somewhere deep in our app; only the Timer would be re-rendered. Nothing else (sideways data loading).
  • There are no subscriptions of any kind that need to be managed.
  • There is no forced UI update in our 'controller'.
  • There is no state in the component. Timer is a dumb component.
  • This approach is unobtrusive; you are not forced to apply certain techniques like keeping all data denormalized and immutable.
  • There is no higher order component that needs configuration; no scopes, lenses or cursors.
  • There is no magic context being passed through components.

Notice

Unlike Object.observe, you cannot track added properties. So remeber to initialize any property you want to observe. Null values work if you don't have any value yet. Observing added properties is impossible to achieve without native Proxy support or dirty checking.

Getting started

Top level api

For the full api, see the API documentation. This is an overview of most important functions available in the mobservable namespace:

observable(value, options?) The observable function is the swiss knife of mobservable and enriches any data structure or function with observable capabilities.

autorun(function) Turns a function into an observer so that it will automatically be re-evaluated if any data values it uses changes.

observer(reactJsComponent) The observer function (and ES6 decorator) from the mobservable-react turns any Reactjs component into a reactive one. From there on it will responds automatically to any relevant change in observable data that was used by its render method.

Examples

Philosophy

Mobservable is inspired by Microsoft Excel and existing TFRP implementations like MeteorJS tracker, knockout and Vue.js.

What others are saying...

Elegant! I love it! ‐ Johan den Haan, CTO of Mendix

We ported the book Notes and Kanban examples to Mobservable. Check out the source to see how this worked out. Compared to the original I was definitely positively surprised. Mobservable seems like a good fit for these problems. ‐ Juho Vepsäläinen, author of "SurviveJS - Webpack and React" and jster.net curator

Great job with Mobservable! Really gives current conventions and libraries a run for their money. ‐ Daniel Dunderfelt

I was reluctant to abandon immutable data and the PureRenderMixin, but I no longer have any reservations. I can't think of any reason not to do things the simple, elegant way you have demonstrated. ‐David Schalk, fpcomplete.com

Contributing

  • Feel free to send pr requests.
  • Use npm test to run the basic test suite, npm run converage for the test suite with coverage and npm run perf for the performance tests.