Registry / http-networking / observable-callback

observable-callback

JSON →
library1.0.3jsnpmunverified

A small RxJS utility (v1.0.3, stable) that creates a callback function which publishes its argument to an observable stream. It wraps an RxJS Subject and returns a tuple of the subject's observable and its next() function. Also supports an optional operator function to transform the observable. Minimal, no other dependencies besides RxJS 6.x or 7.x. Ideal for converting callback-based APIs (e.g., React event handlers) into observable streams.

npm install observable-callback
INSTALL
IMPORT
SIG · OBSERVABLE-CALLBAC
O
observable-callback
http-networkingjavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

observableCallback
✓ import { observableCallback } from 'observable-callback'
✗ const observableCallback = require('observable-callback')
Package is ESM-only; named import required. CommonJS require will fail unless using a bundler that handles ESM.
Observable
✓ import { Observable } from 'rxjs'
✗ import { Observable } from 'observable-callback'
Observable type is not re-exported; must be imported from rxjs.
OperatorFunction
✓ import { OperatorFunction } from 'rxjs'
✗ import { OperatorFunction } from 'observable-callback'
OperatorFunction type used in the overloaded signature; import from rxjs.

Shows creation of observable-callback, subscription, invoking callback, and usage with operator and in React.

import { observableCallback } from 'observable-callback'; import { map } from 'rxjs/operators'; // Basic usage: create callback and observable const [value$, onValue] = observableCallback(); value$.subscribe(value => console.log(value)); // logs 'Hi' onValue('Hi'); // With operator: transform stream const [greeting$, onPlanet] = observableCallback( planet$ => planet$.pipe(map(planet => `Hello ${planet}!`)) ); greeting$.subscribe(console.log); // logs 'Hello world!' onPlanet('world'); // React example import React from 'react'; const [clicks$, onClick] = observableCallback(); clicks$.subscribe(() => console.log('clicked')); const Button = () => <button onClick={onClick}>Click me</button>;
Debug
Known issues
breakingv1.0.2 added support for rxjs@7 as peer dependency. v1.0.0 only supported rxjs@6.
fix
Upgrade to v1.0.2+ or keep rxjs@6.
affects: <1.0.2
gotchaThe callback function is the Subject's next method; calling it with no argument or multiple arguments may cause unexpected behavior since Subject.next expects a single argument.
fix
Always call with exactly one argument of the expected type.
affects: >=0.0.0
gotchaIf the operator function is provided, the first element of the tuple is the observable from operator's result, not the raw subject observable. This may confuse developers expecting the raw subject observable.
fix
When passing an operator, the returned observable is the transformed one; reference the operator if you need the raw subject.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'observable-callback' or its corresponding type declarations.
The package may not be installed or TypeScript cannot resolve it due to missing node_modules or incorrect moduleResolution.
fix
Run npm install observable-callback. Ensure tsconfig has moduleResolution: 'node' or 'node16' and esModuleInterop true.
Module not found: Error: Can't resolve 'observable-callback'
CommonJS require used in a bundler that cannot resolve ESM-only package.
fix
Use import syntax or configure bundler to handle ESM (e.g., webpack with experiments.outputModule).
TypeError: observableCallback is not a function
Incorrect import style: using default import or destructuring from wrong object.
fix
Use named import: import { observableCallback } from 'observable-callback'.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
rxjsrequiredPeer dependency for Observable and Subject types. Must be installed separately.
Agent activity
4 hits · last 30 days
node
4
Resources
observable-callback — npm install observable-callback · libregistry