Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.0 code refactor #35

Merged
merged 23 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a77698d
refactor: isolate algorithm core from API design
johnsoncodehk Jan 11, 2025
b1c20bd
refactor: move updateComputed and notifyEffect functions to global scope
johnsoncodehk Jan 11, 2025
f82e014
refactor: rewrite in function based API
johnsoncodehk Jan 11, 2025
0f5c325
refactor: split untrack function to pauseTracking and resumeTracking
johnsoncodehk Jan 11, 2025
b2207cb
fix: update memoryUsage benchmark to use getDefaultSystem for imports
johnsoncodehk Jan 11, 2025
6bf00fe
refactor: prefix internal functions with underscore for clarity
johnsoncodehk Jan 11, 2025
9db9aa5
refactor: rename internal functions for clarity and organization
johnsoncodehk Jan 11, 2025
a28f5e7
1.0.0-alpha.0
johnsoncodehk Jan 11, 2025
6d0369e
feat: return true when linked a new dep in link function
johnsoncodehk Jan 11, 2025
98cf0cf
1.0.0-alpha.1
johnsoncodehk Jan 11, 2025
0499f48
refactor: restructure computed and effect handling in createSystem
johnsoncodehk Jan 11, 2025
4e5e94e
refactor: abstract flags processing logic
johnsoncodehk Jan 12, 2025
9e63d95
1.0.0-alpha.2
johnsoncodehk Jan 12, 2025
18f8f53
refactor: simplify flags handling in notify and processInnerEffects f…
johnsoncodehk Jan 12, 2025
cc902f2
fix: add flags check before notifying effects in processInnerEffects
johnsoncodehk Jan 12, 2025
048fb61
1.0.0-alpha.3
johnsoncodehk Jan 12, 2025
67b4bca
refactor: consistency internal function names
johnsoncodehk Jan 12, 2025
4a75a1c
refactor: move sample implement to index.ts
johnsoncodehk Jan 12, 2025
dadddc4
chore: update imports in test files
johnsoncodehk Jan 12, 2025
ac19666
refactor: replace computed.is, effect.is options by IsComputed, IsEff…
johnsoncodehk Jan 12, 2025
eef7286
refactor: API finalization
johnsoncodehk Jan 14, 2025
52e9dc5
refactor: remove unused SubscriberFlags value
johnsoncodehk Jan 14, 2025
2912104
chore: remove CHANGELOG.md file
johnsoncodehk Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions CHANGELOG.md

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ export function propagate(link: Link, targetFlag: SubscriberFlags = SubscriberFl
if (subSubs !== undefined) {
propagate(
subSubs,
'notify' in sub
isEffect(sub)
? SubscriberFlags.InnerEffectsPending
: SubscriberFlags.ToCheckDirty
);
} else if ('notify' in sub) {
} else if (isEffect(sub)) {
if (queuedEffectsTail !== undefined) {
queuedEffectsTail.nextNotify = sub;
} else {
Expand Down Expand Up @@ -157,18 +157,18 @@ export function propagate(link: Link, targetFlag: SubscriberFlags = SubscriberFl
export function checkDirty(link: Link): boolean {
do {
const dep = link.dep;
if ('update' in dep) {
if ('flags' in dep) {
const depFlags = dep.flags;
if (depFlags & SubscriberFlags.Dirty) {
if (dep.update()) {
if (isComputed(dep) && updateComputed(dep)) {
const subs = dep.subs!;
if (subs.nextSub !== undefined) {
shallowPropagate(subs);
}
return true;
}
} else if (depFlags & SubscriberFlags.ToCheckDirty) {
if (checkDirty(dep.deps!)) {
if (isComputed(dep) && checkDirty(dep.deps!)) {
if (dep.update()) {
const subs = dep.subs!;
if (subs.nextSub !== undefined) {
Expand Down
6 changes: 3 additions & 3 deletions benchs/complex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ boxplot(() => {
let last = src;
for (let j = 0; j < h; j++) {
const prev = last;
last = computed(() => ({ [`${i}-${j}`]: prev.get() }));
last = computed(() => ({ [`${i}-${j}`]: prev() }));
}
effect(() => last.get());
effect(() => last());
}

yield () => src.set({ upstream: src.get() });
yield () => src({ upstream: src() });
})
.args('h', [1, 10, 100])
.args('w', [1, 10, 100]);
Expand Down
10 changes: 5 additions & 5 deletions benchs/memoryUsage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ console.log(`signal: ${((end - start) / 1024).toFixed(2)} KB`);

start = end;

const computeds = Array.from({ length: 10000 }, (_, i) => computed(() => signals[i].get() + 1));
const computeds = Array.from({ length: 10000 }, (_, i) => computed(() => signals[i]() + 1));

globalThis.gc();
end = process.memoryUsage().heapUsed;
Expand All @@ -21,7 +21,7 @@ console.log(`computed: ${((end - start) / 1024).toFixed(2)} KB`);

start = end;

Array.from({ length: 10000 }, (_, i) => effect(() => computeds[i].get()));
Array.from({ length: 10000 }, (_, i) => effect(() => computeds[i]()));

globalThis.gc();
end = process.memoryUsage().heapUsed;
Expand All @@ -38,12 +38,12 @@ for (let i = 0; i < w; i++) {
let last = src;
for (let j = 0; j < h; j++) {
const prev = last;
last = computed(() => prev.get() + 1);
effect(() => last.get());
last = computed(() => prev() + 1);
effect(() => last());
}
}

src.set(src.get() + 1);
src(src() + 1);

globalThis.gc();
end = process.memoryUsage().heapUsed;
Expand Down
8 changes: 4 additions & 4 deletions benchs/propagate.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { run, bench, boxplot } from 'mitata';
import { bench, boxplot, run } from 'mitata';
import { computed, effect, signal } from '../esm/index.mjs';

boxplot(() => {
Expand All @@ -10,11 +10,11 @@ boxplot(() => {
let last = src;
for (let j = 0; j < h; j++) {
const prev = last;
last = computed(() => prev.get() + 1);
last = computed(() => prev() + 1);
}
effect(() => last.get());
effect(() => last());
}
yield () => src.set(src.get() + 1);
yield () => src(src() + 1);
})
.args('h', [1, 10, 100])
.args('w', [1, 10, 100]);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alien-signals",
"version": "0.6.0",
"version": "1.0.0-alpha.3",
"sideEffects": false,
"license": "MIT",
"description": "The lightest signal library.",
Expand Down Expand Up @@ -38,7 +38,7 @@
"build:esm": "esbuild src/index.ts --bundle --format=esm --outfile=esm/index.mjs",
"build:cjs": "esbuild src/index.ts --bundle --format=cjs --outfile=cjs/index.cjs",
"test": "vitest run",
"bench": "npm run build:esm && node --jitless --expose-gc benchs/propagate.mjs && node --jitless --expose-gc benchs/complex.mjs",
"bench": "npm run build:esm && node --jitless --expose-gc benchs/propagate.mjs",
"bench:memory": "npm run build:esm && node --expose-gc benchs/memoryUsage.mjs"
},
"devDependencies": {
Expand Down
13 changes: 0 additions & 13 deletions src/batch.ts

This file was deleted.

64 changes: 0 additions & 64 deletions src/computed.ts

This file was deleted.

77 changes: 0 additions & 77 deletions src/effect.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/effectScope.ts

This file was deleted.

Loading
Loading