Skip to content

Commit 8e7dd8c

Browse files
authored
Merge pull request #67 from gadget-inc/upgrade-node
Add nix and upgrade node
2 parents 21cdb88 + 1678862 commit 8e7dd8c

File tree

10 files changed

+183
-76
lines changed

10 files changed

+183
-76
lines changed

.envrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use flake
2+
3+
source_env_if_exists .envrc.local

.github/actions/setup-test-env/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ runs:
88
- name: Install Node.js
99
uses: actions/setup-node@v3
1010
with:
11-
node-version: 16
11+
node-version: 21
1212

1313
- uses: pnpm/action-setup@v2
1414
name: Install pnpm
1515
id: pnpm-install
1616
with:
17-
version: 7
17+
version: 8
1818
run_install: false
1919

2020
- name: Get pnpm store directory

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
.direnv
12
dist
23
node_modules
34
yarn.lock
45
vscode-profile*
56
isolate-*
6-
flamegraph.html
7+
flamegraph.html
8+
*.perf

Benchmarking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ node --prof-process isolate-*.log
3535
You can postprocess the generated `isolate-0x<something>.log` file into the data `flamegraph` expects, and then feed it to `flamegraph` to see a visual breakdown of performance. You can do that in one command like so:
3636

3737
```shell
38-
node --prof-process --preprocess -j isolate-*.log | p flamebearer
38+
node --prof-process --preprocess -j isolate-*.log | pnpm flamebearer
3939
```
4040

4141
#### CPU profiling with VSCode

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
description = "mobx-quick-tree development environment";
3+
4+
inputs = {
5+
flake-utils.url = "github:numtide/flake-utils";
6+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
7+
};
8+
9+
outputs = { self, flake-utils, nixpkgs }:
10+
(flake-utils.lib.eachSystem [
11+
"x86_64-linux"
12+
"x86_64-darwin"
13+
"aarch64-darwin"
14+
]
15+
(system: nixpkgs.lib.fix (flake:
16+
let
17+
pkgs = nixpkgs.legacyPackages.${system};
18+
in
19+
rec {
20+
21+
packages =
22+
rec {
23+
bash = pkgs.bash;
24+
nodejs = pkgs.nodejs_21;
25+
pnpm = pkgs.nodejs_21.pkgs.pnpm;
26+
};
27+
28+
devShell = pkgs.mkShell {
29+
packages = builtins.attrValues packages;
30+
};
31+
}
32+
)));
33+
}

src/class-model.ts

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import type { IModelType as MSTIModelType, ModelActions } from "mobx-state-tree"
33
import { types as mstTypes } from "mobx-state-tree";
44
import "reflect-metadata";
55
import { RegistrationError } from "./errors";
6-
import { $fastInstantiator, buildFastInstantiator } from "./fast-instantiator";
6+
import { buildFastInstantiator } from "./fast-instantiator";
77
import { defaultThrowAction, mstPropsFromQuickProps, propsFromModelPropsDeclaration } from "./model";
88
import {
99
$env,
1010
$identifier,
11+
$memoizedKeys,
12+
$memos,
1113
$originalDescriptor,
1214
$parent,
1315
$quickType,
@@ -23,8 +25,6 @@ import type {
2325
IAnyType,
2426
IClassModelType,
2527
IStateTreeNode,
26-
InputTypesForModelProps,
27-
InputsForModel,
2828
InstantiateContext,
2929
ModelPropertiesDeclaration,
3030
ModelViews,
@@ -59,8 +59,6 @@ const metadataPrefix = "mqt:properties";
5959
const viewKeyPrefix = `${metadataPrefix}:view`;
6060
const actionKeyPrefix = `${metadataPrefix}:action`;
6161
const volatileKeyPrefix = `${metadataPrefix}:volatile`;
62-
const $memos = Symbol.for("mqt:class-model-memos");
63-
const $memoizedKeys = Symbol.for("mqt:class-model-memoized-keys");
6462

6563
/**
6664
* A map of property keys to indicators for how that property should behave on the registered class
@@ -82,40 +80,19 @@ class BaseClassModel {
8280
return extend(this, props);
8381
}
8482

83+
/** Properties set in the fast instantiator compiled constructor, included here for type information */
84+
[$readOnly]!: true;
85+
[$type]!: IClassModelType<TypesForModelPropsDeclaration<any>>;
8586
/** @hidden */
8687
readonly [$env]?: any;
8788
/** @hidden */
8889
readonly [$parent]?: IStateTreeNode | null;
8990
/** @hidden */
90-
[$memos] = null;
91+
[$identifier]?: any;
9192
/** @hidden */
92-
[$memoizedKeys] = null;
93+
[$memos]!: Record<string, any> | null;
9394
/** @hidden */
94-
[$identifier]?: any;
95-
96-
constructor(
97-
snapshot: InputsForModel<InputTypesForModelProps<TypesForModelPropsDeclaration<any>>> | undefined,
98-
context: InstantiateContext,
99-
parent: IStateTreeNode | null,
100-
/** @hidden */ hackyPreventInitialization = false
101-
) {
102-
if (hackyPreventInitialization) {
103-
return;
104-
}
105-
106-
this[$env] = context.env;
107-
this[$parent] = parent;
108-
109-
(this.constructor as IClassModelType<any>)[$fastInstantiator](this as any, snapshot, context);
110-
}
111-
112-
get [$readOnly]() {
113-
return true;
114-
}
115-
116-
get [$type]() {
117-
return this.constructor as IClassModelType<TypesForModelPropsDeclaration<any>>;
118-
}
95+
[$memoizedKeys]!: Record<string, boolean> | null;
11996
}
12097

12198
/**
@@ -162,7 +139,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
162139
tags?: RegistrationTags<Instance>,
163140
name?: string
164141
) {
165-
const klass = object as any as IClassModelType<any>;
142+
let klass = object as any as IClassModelType<any>;
166143
const mstActions: ModelActions = {};
167144
const mstViews: ModelViews = {};
168145
const mstVolatiles: Record<string, VolatileMetadata> = {};
@@ -263,6 +240,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
263240
}
264241
case "volatile": {
265242
mstVolatiles[metadata.property] = metadata;
243+
break;
266244
}
267245
}
268246
}
@@ -310,7 +288,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
310288
(klass as any).mstType = (klass as any).mstType.volatile((self: any) => initializeVolatiles({}, self, mstVolatiles));
311289
}
312290

313-
klass[$fastInstantiator] = buildFastInstantiator(klass);
291+
klass = buildFastInstantiator(klass);
314292
(klass as any)[$registered] = true;
315293

316294
return klass as any;

0 commit comments

Comments
 (0)