Skip to content

Commit a4a4a1c

Browse files
committed
feat(agera,kida): mark certain functions as no side effects
1 parent dcd271d commit a4a4a1c

File tree

11 files changed

+21
-0
lines changed

11 files changed

+21
-0
lines changed

packages/agera/src/effect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export function effectScope(
147147
* Create effect scope runner which will share the same scope instance.
148148
* @returns The effect scope runner.
149149
*/
150+
/* @__NO_SIDE_EFFECTS__ */
150151
export function createEffectScope() {
151152
return runEffectScopeInstance.bind(null, createEffectScopeInstance()) as typeof effectScope
152153
}

packages/agera/src/signal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function signal<T>(): WritableSignal<T | undefined>
9494
*/
9595
export function signal<T>(value: T): WritableSignal<T>
9696

97+
/* @__NO_SIDE_EFFECTS__ */
9798
export function signal<T>(value?: T): WritableSignal<T | undefined> {
9899
return createSignal(signalGetterSetter, {
99100
[$$value]: value,
@@ -129,6 +130,7 @@ function signalGetterSetter<T>(this: Signal<T>, ...value: [T]): T | void {
129130
* @param compute - The function to compute the value.
130131
* @returns A signal.
131132
*/
133+
/* @__NO_SIDE_EFFECTS__ */
132134
export function computed<T>(compute: Compute<T>): ReadableSignal<T> {
133135
return createSignal(computedGetter, {
134136
[$$value]: undefined,
@@ -165,6 +167,7 @@ export function morph<T, C extends Partial<Morph<T>>>(
165167
context: C
166168
): ReadableSignal<T>
167169

170+
/* @__NO_SIDE_EFFECTS__ */
168171
export function morph<T, C extends Partial<Morph<T>>>(
169172
$signal: WritableSignal<T>,
170173
context: C

packages/kida/src/channel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function abortableRun(
5252
* @param mapErrorValue - Function to map the error value. Default is to get the error message.
5353
* @returns A tuple with the task, state and error signal.
5454
*/
55+
/* @__NO_SIDE_EFFECTS__ */
5556
export function channel<E = string>(
5657
tasks: TasksSet,
5758
mapErrorValue: (error: unknown) => E = error => (error as Error).message as E

packages/kida/src/external.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function lazyGetterSetter<T>(this: External<T>, ...value: [T]): T | void {
3333
* @param factory - The factory function.
3434
* @returns The external signal.
3535
*/
36+
/* @__NO_SIDE_EFFECTS__ */
3637
export function external<T>(
3738
factory: ExternalFactory<T>
3839
) {

packages/kida/src/lazy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function lazyGetter<T>(this: Morph<T>) {
2626
* @param factory - The factory function.
2727
* @returns The lazy signal.
2828
*/
29+
/* @__NO_SIDE_EFFECTS__ */
2930
export function lazy<T>(factory: LazyFactory<T>) {
3031
return morph(signal(factory as T), {
3132
[$$get]: lazyGetter

packages/kida/src/list.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function atIndex<T>(
3030
index: number | ReadableSignal<number>
3131
): ReadableSignal<T>
3232

33+
/* @__NO_SIDE_EFFECTS__ */
3334
export function atIndex<T>(
3435
$list: ReadableSignal<T[]> | WritableSignal<T[]>,
3536
index: number | ReadableSignal<number>
@@ -101,6 +102,7 @@ export function unshift<T>($list: WritableSignal<T[]>, ...values: T[]) {
101102
* @param index - The index to get.
102103
* @returns The value at the index.
103104
*/
105+
/* @__NO_SIDE_EFFECTS__ */
104106
export function getIndex<T>($list: ReadableSignal<T[]>, index: number) {
105107
return $list()[index]
106108
}
@@ -142,6 +144,7 @@ export function clearList<T>($list: WritableSignal<T[]>) {
142144
* @param value - The value to check.
143145
* @returns Whether the list signal includes the value.
144146
*/
147+
/* @__NO_SIDE_EFFECTS__ */
145148
export function includes<T>($list: ReadableSignal<T[]>, value: T) {
146149
return $list().includes(value)
147150
}

packages/kida/src/map.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function atKey<T extends AnyCollection>(
3232
key: keyof T | ReadableSignal<keyof T>
3333
): ReadableSignal<T[keyof T]>
3434

35+
/* @__NO_SIDE_EFFECTS__ */
3536
export function atKey<T extends AnyCollection>(
3637
$map: ReadableSignal<T> | WritableSignal<T>,
3738
key: keyof T | ReadableSignal<keyof T>
@@ -45,6 +46,7 @@ export function atKey<T extends AnyCollection>(
4546
* @param key - The key to get.
4647
* @returns The value.
4748
*/
49+
/* @__NO_SIDE_EFFECTS__ */
4850
export function getKey<T extends AnyCollection>($map: ReadableSignal<T>, key: keyof T) {
4951
return $map()[key]
5052
}
@@ -97,6 +99,7 @@ export function clearMap<T extends AnyCollection>($map: WritableSignal<T>) {
9799
* @param key - The key to check.
98100
* @returns Whether the map signal has the key.
99101
*/
102+
/* @__NO_SIDE_EFFECTS__ */
100103
export function has<T extends AnyCollection>($map: ReadableSignal<T>, key: keyof T) {
101104
return key in $map()
102105
}

packages/kida/src/paced.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { RateLimiter } from './types/index.js'
1111
* @param rateLimiter - The rate limiter function.
1212
* @returns The paced signal.
1313
*/
14+
/* @__NO_SIDE_EFFECTS__ */
1415
export function paced<T>(
1516
$signal: WritableSignal<T>,
1617
rateLimiter: RateLimiter

packages/kida/src/record.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const flatHandler = /* @__PURE__ */ createProxyHandler(child => child)
2323
* @param source - Source signal.
2424
* @returns A record signal.
2525
*/
26+
/* @__NO_SIDE_EFFECTS__ */
2627
export function record<T>(source: T) {
2728
return recordBase(toSignal(source), flatHandler) as T extends AnyWritableSignal
2829
? WritableRecord<T>
@@ -39,6 +40,7 @@ const deepHandler = /* @__PURE__ */ createProxyHandler(deepRecord)
3940
* @param source - Source signal.
4041
* @returns A deep record signal.
4142
*/
43+
/* @__NO_SIDE_EFFECTS__ */
4244
export function deepRecord<T>(source: T) {
4345
return recordBase(toSignal(source), deepHandler) as T extends AnyWritableSignal
4446
? WritableDeepRecord<T>

packages/kida/src/tasks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function Tasks() {
1313
* @param tasks - Tasks queue.
1414
* @returns Promise that resolves when all running tasks are finished.
1515
*/
16+
/* @__NO_SIDE_EFFECTS__ */
1617
export function allTasks(tasks: TasksSet) {
1718
return Promise.allSettled([...tasks])
1819
}
@@ -47,6 +48,7 @@ export function addTask<T = void>(
4748
* @param tasks - Tasks queue.
4849
* @returns The task runner.
4950
*/
51+
/* @__NO_SIDE_EFFECTS__ */
5052
export function createTasksRunner(tasks: TasksSet) {
5153
return (fn: () => Promise<unknown>) => addTask(tasks, fn())
5254
}

0 commit comments

Comments
 (0)