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

micro-observables

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micro-observables - npm Package Compare versions

Comparing version 1.5.0-rc4 to 1.5.0-rc5

2

batchingForReactDom.js
const ReactDOM = require("react-dom");
require("./lib").setBatchedUpdater(ReactDOM.unstable_batchedUpdates);
require("./dist").setBatchedUpdater(ReactDOM.unstable_batchedUpdates);
const ReactNative = require("react-native");
require("./lib").setBatchedUpdater(ReactNative.unstable_batchedUpdates);
require("./dist").setBatchedUpdater(ReactNative.unstable_batchedUpdates);
{
"name": "micro-observables",
"version": "1.5.0-rc4",
"version": "1.5.0-rc5",
"description": "A simple Observable library that can be used for easy state management in React applications.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -9,3 +9,3 @@ # Micro-observables

- **⚛️ React support:** Out-of-the-box React support based on React Hooks
- **🐥 Lightweight:** The whole source code is made of less than 400 lines of code, resulting in **6kb** production bundle
- **🐥 Lightweight:** The whole source code is made of less than 400 lines of code, resulting in a **6kb** production bundle
- **🔥 Peformant:** Observables are evaluated only when needed. Micro-observables also supports [React and React Native batching](#react-batching), minimizing the amount of re-renders

@@ -355,2 +355,29 @@ - **🔮 Debuggable:** Micro-observables does not rely on ES6 proxies, making it easy to identify lines of code that trigger renders. Code execution is easy to follow, making debugging straightforward

#### Observable.compute(compute: () => value)
`Observable.compute()` is your **silver bullet** when it is too difficult to create a new observable with the usual `transform()`, `onlyIf()`, `from()` or `latest()` methods. It is especially useful when dealing with complex data structures. It takes a function that computes a new value by directly accessing values from other observables and returns a new observable containing the result of this computation.
**How it works:** Each time the observable is evaluated, it calls the provided `compute` function and automatically tracks the observables that are used by the computation. It then registers these observables as input, ensuring that the new observable will be updated if one of them changes. If you are familiar with MobX, it works the same as the `@computed` observables.
```ts
const authors = new Map([
[0, observable("Kipling")],
[1, observable("Shakespeare")],
[2, observable("Austen")],
]);
const books = observable([
{ title: "The Jungle Book", authorId: 0 },
{ title: "Pride and Prejudice", authorId: 2 },
{ title: "Persuasion", authorId: 2 },
]);
const booksWithAuthors = Observable.compute(() =>
books.get().map(book => ({ title: book.title, author: authors.get(book.authorId).get() }))
);
assert.deepEqual(booksWithAuthors.get(), [
{ title: "The Jungle Book", author: "Kipling" },
{ title: "Pride and Prejudice", author: "Austen" },
{ title: "Persuasion", author: "Austen" },
]);
```
#### Observable.fromPromise(promise, onError?: (error) => value)

@@ -370,3 +397,3 @@

#### Observable.batch(block)
#### Observable.batch(block: () => void)

@@ -381,8 +408,8 @@ Group several observable modifications for batching. You usually don't need to call this function, but it can sometimes be useful for better control over batching. You can learn more about batching and how to enable it [here](#react-batching).

location =>
Observable.batch(l => {
location.set(l);
Observable.batch(() => {
location.set(location);
permissionDenied.set(false);
}),
error =>
Observable.batch(l => {
Observable.batch(() => {
location.set(null);

@@ -389,0 +416,0 @@ permissionDenied.set(true);

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