start moving signal types over

blockless
Rich Harris 2 years ago
parent 4e9cf14194
commit 6be359bbc4

@ -6,7 +6,7 @@ import { CLEAN, SOURCE } from '../constants.js';
/** /**
* @template V * @template V
* @param {V} initial_value * @param {V} initial_value
* @returns {import('../types.js').Source<V>} * @returns {import('./types.js').Source<V>}
*/ */
/*#__NO_SIDE_EFFECTS__*/ /*#__NO_SIDE_EFFECTS__*/
export function source(initial_value) { export function source(initial_value) {
@ -16,7 +16,7 @@ export function source(initial_value) {
/** /**
* @template V * @template V
* @param {V} initial_value * @param {V} initial_value
* @returns {import('../types.js').Source<V>} * @returns {import('./types.js').Source<V>}
*/ */
/*#__NO_SIDE_EFFECTS__*/ /*#__NO_SIDE_EFFECTS__*/
export function mutable_source(initial_value) { export function mutable_source(initial_value) {
@ -36,7 +36,7 @@ export function mutable_source(initial_value) {
* @template V * @template V
* @param {import('../types.js').SignalFlags} flags * @param {import('../types.js').SignalFlags} flags
* @param {V} value * @param {V} value
* @returns {import('../types.js').Source<V> | import('../types.js').Source<V> & import('../types.js').SourceDebug} * @returns {import('./types.js').Source<V> | import('./types.js').Source<V> & import('./types.js').SourceDebug}
*/ */
function create_source_signal(flags, value) { function create_source_signal(flags, value) {
if (DEV) { if (DEV) {

@ -50,7 +50,7 @@ export function store_get(store, store_name, stores) {
/** /**
* @template V * @template V
* @param {import('../types.js').Store<V> | null | undefined} store * @param {import('../types.js').Store<V> | null | undefined} store
* @param {import('../types.js').Source<V>} source * @param {import('./types.js').Source<V>} source
*/ */
function connect_store_to_signal(store, source) { function connect_store_to_signal(store, source) {
if (store == null) { if (store == null) {

@ -0,0 +1,19 @@
import type { Computation, EqualsFunctions, SignalFlags } from '../types';
export type Source<V = unknown> = {
/** consumers: Signals that read from the current signal */
c: null | Computation[];
/** equals: For value equality */
e: null | EqualsFunctions;
/** flags: The types that the signal represent, as a bitwise value */
f: SignalFlags;
/** value: The latest value for this signal */
v: V;
// write version
w: number;
};
export type SourceDebug = {
/** This is DEV only */
inspect: Set<Function>;
};

@ -1,4 +1,5 @@
import { DERIVED, EFFECT, RENDER_EFFECT, SOURCE, PRE_EFFECT, STATE_SYMBOL } from './constants.js'; import { DERIVED, EFFECT, RENDER_EFFECT, SOURCE, PRE_EFFECT, STATE_SYMBOL } from './constants.js';
import type { Source, SourceDebug } from './reactivity/types.js';
// Put all internal types in this file. Once we convert to JSDoc, we can make this a d.ts file // Put all internal types in this file. Once we convert to JSDoc, we can make this a d.ts file
@ -55,24 +56,6 @@ export type ComponentContext = {
// (effects and derived signals). Thus we can improve the memory profile at the slight cost // (effects and derived signals). Thus we can improve the memory profile at the slight cost
// of some runtime performance. // of some runtime performance.
export type Source<V = unknown> = {
/** consumers: Signals that read from the current signal */
c: null | Computation[];
/** equals: For value equality */
e: null | EqualsFunctions;
/** flags: The types that the signal represent, as a bitwise value */
f: SignalFlags;
/** value: The latest value for this signal */
v: V;
// write version
w: number;
};
export type SourceDebug = {
/** This is DEV only */
inspect: Set<Function>;
};
export type Computation<V = unknown> = { export type Computation<V = unknown> = {
/** consumers: Signals that read from the current signal */ /** consumers: Signals that read from the current signal */
c: null | Computation[]; c: null | Computation[];

Loading…
Cancel
Save