Socket
Socket
Sign inDemoInstall

@starbeam/reactive

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@starbeam/reactive - npm Package Compare versions

Comparing version 0.8.10-unstable.84e5619 to 0.8.10-unstable.9b5a07d

CHANGELOG.md

56

package.json
{
"name": "@starbeam/reactive",
"version": "0.8.10-unstable.84e5619",
"type": "module",
"main": "index.ts",
"types": "index.ts",
"version": "0.8.10-unstable.9b5a07d",
"main": "dist/index.cjs",
"types": "dist/index.d.ts",
"exports": {
"default": "./index.ts"
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.cjs"
},
"publishConfig": {
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.cjs"
}
},
"main": "dist/index.cjs",
"types": "dist/index.d.ts"
},
"starbeam": {
"type": "library:public"
},
"dependencies": {
"@starbeam/core-utils": "0.8.10-unstable.9b5a07d",
"@starbeam/interfaces": "0.8.10-unstable.9b5a07d",
"@starbeam/shared": "1.3.8-unstable.9b5a07d",
"@starbeam/tags": "0.0.1-unstable.9b5a07d",
"@starbeam/verify": "0.8.10-unstable.9b5a07d"
},
"devDependencies": {
"@starbeam-dev/compile": "^1.1.0",
"@starbeam-dev/eslint-plugin": "^1.0.4",
"rollup": "^4.0.2"
},
"files": [
"dist",
"README.md",
"CHANGELOG.md",
"LICENSE.md"
],
"scripts": {
"build": "rollup -c",
"test:lint": "eslint . --max-warnings 0",
"test:specs": "vitest --run",
"test:specs": "vitest --run --pool forks",
"test:types": "tsc -b"
},
"dependencies": {
"@starbeam/core-utils": "0.8.10-unstable.84e5619",
"@starbeam/interfaces": "0.8.10-unstable.84e5619",
"@starbeam/shared": "1.3.8-unstable.84e5619",
"@starbeam/tags": "0.0.1-unstable.84e5619",
"@starbeam/verify": "0.8.10-unstable.84e5619"
},
"devDependencies": {
"@starbeam/eslint-plugin": "workspace:^",
"@starbeam-dev/build-support": "workspace:^",
"rollup": "^3.29.2"
}
}
}
This package contains the implementations of the reactive primitives.
Reactive primitives must be used with an implementation of `Runtime`, which
basically means that they must be used together with `@reactive/runtime`.
basically means that they must be used together with `@starbeam/runtime`.
Higher-level packages, such as `@starbeam/universal`, `@starbeam/resource` and
the renderers include `@starbeam/runtime` as a dependency.
> The primitives themselves, and higher-level concepts built on the primitives are

@@ -56,2 +59,4 @@ > agnostic to the runtime, primarily to clearly mark the runtime interface and

> You can think of a marker as a kind of cell without a value.
A marker has these fundamental operations:

@@ -68,1 +73,74 @@

> of that key will not invalidate the formula.
### Formula
A formula is a function that computes a reactive value. A formula's dependencies
is the set of cells that were accessed during its last computation.
A formula is a [reactive value](#the-reactive-protocol). Whenever the formula
is `read()`, it recomputes its value. It is also a function. Calling the formula
has the same behavior as calling the formula's `read()` method.
#### Cached Formula
A cached formula behaves like a formula, but it only recomputes its value when
one of its dependencies changes.
## Formula vs. CachedFormula
Both formulas and cached formulas are reactive values. You can render either one
(see `@starbeam/runtime` for more information). In either case, when the formula
is recomputed, its dependencies are updated, and the formula's renderers will
receive readiness notifications when any of the new dependencies change.
The difference is that a cached formula will only recompute when one of its
dependencies changes.
Normal formulas are suitable for **mixed-reactive environments**, where a
Starbeam formula uses both Starbeam reactive values **and** a framework's native
reactive values.
For example, consider this situation when using the React renderer:
```ts
function Counter() {
const [reactCount, setReactCount] = useState(0);
const starbeamCount = useSetup(() => {
const count = Cell(0);
return {
increment: () => {
count.current++;
},
get count() {
return count.read();
},
};
});
return useReactive(() => {
<p>
React count: {reactCount}
<button onClick={() => setReactCount(reactCount + 1)}>Increment</button>
</p>;
<p>
Starbeam count: {starbeamCount.count}
<button onClick={starbeamCount.increment}>Increment</button>
</p>;
});
}
```
Under the hood, `useReactive` uses a normal formula, which will result in an
updated output whenever either `reactCount` or `starbeamCount.count` changes.
- If `reactCount` changes, React will re-render the component, and the formula
will be recomputed.
- If `starbeamCount.count` changes, the formula will be recomputed, and React
will re-render the component.
In practice, this makes `Formula` a good default choice for mixed-reactive
environments. You can always use `CachedFormula` if you are confident that your
formula doesn't use any reactive values external to Starbeam to optimize your
code further.
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