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

Add nix and upgrade node #67

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use flake

source_env_if_exists .envrc.local
4 changes: 2 additions & 2 deletions .github/actions/setup-test-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ runs:
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 21

- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 7
version: 8
run_install: false

- name: Get pnpm store directory
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.direnv
dist
node_modules
yarn.lock
vscode-profile*
isolate-*
flamegraph.html
flamegraph.html
*.perf
2 changes: 1 addition & 1 deletion Benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ node --prof-process isolate-*.log
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:

```shell
node --prof-process --preprocess -j isolate-*.log | p flamebearer
node --prof-process --preprocess -j isolate-*.log | pnpm flamebearer
```

#### CPU profiling with VSCode
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
description = "mobx-quick-tree development environment";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};

outputs = { self, flake-utils, nixpkgs }:
(flake-utils.lib.eachSystem [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
]
(system: nixpkgs.lib.fix (flake:
let
pkgs = nixpkgs.legacyPackages.${system};
in
rec {

packages =
rec {
bash = pkgs.bash;
nodejs = pkgs.nodejs_21;
pnpm = pkgs.nodejs_21.pkgs.pnpm;
};

devShell = pkgs.mkShell {
packages = builtins.attrValues packages;
};
}
)));
}
46 changes: 12 additions & 34 deletions src/class-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import type { IModelType as MSTIModelType, ModelActions } from "mobx-state-tree"
import { types as mstTypes } from "mobx-state-tree";
import "reflect-metadata";
import { RegistrationError } from "./errors";
import { $fastInstantiator, buildFastInstantiator } from "./fast-instantiator";
import { buildFastInstantiator } from "./fast-instantiator";
import { defaultThrowAction, mstPropsFromQuickProps, propsFromModelPropsDeclaration } from "./model";
import {
$env,
$identifier,
$memoizedKeys,
$memos,
$originalDescriptor,
$parent,
$quickType,
Expand All @@ -23,8 +25,6 @@ import type {
IAnyType,
IClassModelType,
IStateTreeNode,
InputTypesForModelProps,
InputsForModel,
InstantiateContext,
ModelPropertiesDeclaration,
ModelViews,
Expand Down Expand Up @@ -59,8 +59,6 @@ const metadataPrefix = "mqt:properties";
const viewKeyPrefix = `${metadataPrefix}:view`;
const actionKeyPrefix = `${metadataPrefix}:action`;
const volatileKeyPrefix = `${metadataPrefix}:volatile`;
const $memos = Symbol.for("mqt:class-model-memos");
const $memoizedKeys = Symbol.for("mqt:class-model-memoized-keys");

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

/** Properties set in the fast instantiator compiled constructor, included here for type information */
[$readOnly]!: true;
[$type]!: IClassModelType<TypesForModelPropsDeclaration<any>>;
/** @hidden */
readonly [$env]?: any;
/** @hidden */
readonly [$parent]?: IStateTreeNode | null;
/** @hidden */
[$memos] = null;
[$identifier]?: any;
/** @hidden */
[$memoizedKeys] = null;
[$memos]!: Record<string, any> | null;
/** @hidden */
[$identifier]?: any;

constructor(
snapshot: InputsForModel<InputTypesForModelProps<TypesForModelPropsDeclaration<any>>> | undefined,
context: InstantiateContext,
parent: IStateTreeNode | null,
/** @hidden */ hackyPreventInitialization = false
) {
if (hackyPreventInitialization) {
return;
}

this[$env] = context.env;
this[$parent] = parent;

(this.constructor as IClassModelType<any>)[$fastInstantiator](this as any, snapshot, context);
}

get [$readOnly]() {
return true;
}

get [$type]() {
return this.constructor as IClassModelType<TypesForModelPropsDeclaration<any>>;
}
[$memoizedKeys]!: Record<string, boolean> | null;
}

/**
Expand Down Expand Up @@ -162,7 +139,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
tags?: RegistrationTags<Instance>,
name?: string
) {
const klass = object as any as IClassModelType<any>;
let klass = object as any as IClassModelType<any>;
const mstActions: ModelActions = {};
const mstViews: ModelViews = {};
const mstVolatiles: Record<string, VolatileMetadata> = {};
Expand Down Expand Up @@ -263,6 +240,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
}
case "volatile": {
mstVolatiles[metadata.property] = metadata;
break;
}
}
}
Expand Down Expand Up @@ -310,7 +288,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
(klass as any).mstType = (klass as any).mstType.volatile((self: any) => initializeVolatiles({}, self, mstVolatiles));
}

klass[$fastInstantiator] = buildFastInstantiator(klass);
klass = buildFastInstantiator(klass);
(klass as any)[$registered] = true;

return klass as any;
Expand Down
Loading
Loading