Skip to content

Commit

Permalink
Merge branch 'main' into 230802-minimal-extend-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Aug 23, 2023
2 parents f32c66e + c14f8bf commit 0987732
Show file tree
Hide file tree
Showing 26 changed files with 224 additions and 185 deletions.
42 changes: 42 additions & 0 deletions .changeset/cool-snakes-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
"@latticexyz/recs": minor
"@latticexyz/std-client": major
---

- Moved `createActionSystem` from `std-client` to `recs` package and updated it to better support v2 sync stack.

If you want to use `createActionSystem` alongside `syncToRecs`, you'll need to pass in arguments like so:

```ts
import { syncToRecs } from "@latticexyz/store-sync/recs";
import { createActionSystem } from "@latticexyz/recs/deprecated";
import { from, mergeMap } from "rxjs";

const { blockLogsStorage$, waitForTransaction } = syncToRecs({
world,
...
});

const txReduced$ = blockLogsStorage$.pipe(
mergeMap(({ operations }) => from(operations.map((op) => op.log?.transactionHash).filter(isDefined)))
);

const actionSystem = createActionSystem(world, txReduced$, waitForTransaction);
```

- Fixed a bug in `waitForComponentValueIn` that caused the promise to not resolve if the component value was already set when the function was called.

- Fixed a bug in `createActionSystem` that caused optimistic updates to be incorrectly propagated to requirement checks. To fix the bug, you must now pass in the full component object to the action's `updates` instead of just the component name.

```diff
actions.add({
updates: () => [
{
- component: "Resource",
+ component: Resource,
...
}
],
...
});
```
2 changes: 1 addition & 1 deletion packages/recs/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export default {
preset: "ts-jest",
testEnvironment: "node",
roots: ["tests"],
roots: ["src"],
moduleNameMapper: {
// jest can't handle esm imports, so we import the typescript source instead
"^@latticexyz/common$": "<rootDir>/../common/src/index.ts",
Expand Down
14 changes: 12 additions & 2 deletions packages/recs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@
"license": "MIT",
"type": "module",
"exports": {
".": "./dist/index.js"
".": "./dist/index.js",
"./deprecated": "./dist/deprecated/index.js"
},
"typesVersions": {
"*": {
"index": [
"./src/index.ts"
],
"deprecated": [
"./src/deprecated/index.ts"
]
}
},
"types": "src/index.ts",
"scripts": {
"build": "pnpm run build:js",
"build:js": "tsup",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
componentValueEquals,
getEntitiesWithValue,
overridableComponent,
} from "../src/Component";
import { Type } from "../src/constants";
import { createEntity, getEntitySymbol } from "../src/Entity";
import { AnyComponent, Entity, World } from "../src/types";
import { createWorld } from "../src/World";
} from "./Component";
import { Type } from "./constants";
import { createEntity, getEntitySymbol } from "./Entity";
import { AnyComponent, Entity, World } from "./types";
import { createWorld } from "./World";

describe("Component", () => {
let world: World;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineComponent, getComponentValue, hasComponent, withValue } from "../src/Component";
import { Type } from "../src/constants";
import { createEntity } from "../src/Entity";
import { World } from "../src/types";
import { createWorld } from "../src/World";
import { defineComponent, getComponentValue, hasComponent, withValue } from "./Component";
import { Type } from "./constants";
import { createEntity } from "./Entity";
import { World } from "./types";
import { createWorld } from "./World";

describe("Entity", () => {
let world: World;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
componentValueEquals,
getEntitiesWithValue,
overridableComponent,
} from "../src/Component";
import { createIndexer } from "../src/Indexer";
import { Type } from "../src/constants";
import { createEntity, getEntitySymbol } from "../src/Entity";
import { AnyComponent, Entity, World } from "../src/types";
import { createWorld } from "../src/World";
} from "./Component";
import { createIndexer } from "./Indexer";
import { Type } from "./constants";
import { createEntity, getEntitySymbol } from "./Entity";
import { AnyComponent, Entity, World } from "./types";
import { createWorld } from "./World";

describe("Indexer", () => {
let world: World;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineComponent as defineComponentV2, setComponent as setComponentV2 } from "../src/Component";
import { createWorld as createWorldV2 } from "../src/World";
import { createEntity as createEntityV2 } from "../src/Entity";
import { Type as TypeV2 } from "../src/constants";
import { HasValue as HasValueV2 } from "../src/Query";
import { defineSystem } from "../src/System";
import { defineComponent as defineComponentV2, setComponent as setComponentV2 } from "./Component";
import { createWorld as createWorldV2 } from "./World";
import { createEntity as createEntityV2 } from "./Entity";
import { Type as TypeV2 } from "./constants";
import { HasValue as HasValueV2 } from "./Query";
import { defineSystem } from "./System";

export function timeIt(fn: () => unknown) {
const start = Date.now();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineComponent, removeComponent, setComponent, withValue } from "../src/Component";
import { UpdateType, Type } from "../src/constants";
import { createEntity } from "../src/Entity";
import { defineComponent, removeComponent, setComponent, withValue } from "./Component";
import { UpdateType, Type } from "./constants";
import { createEntity } from "./Entity";
import {
Has,
Not,
Expand All @@ -12,9 +12,9 @@ import {
ProxyRead,
ProxyExpand,
runQuery,
} from "../src/Query";
import { Component, Entity, World } from "../src/types";
import { createWorld } from "../src/World";
} from "./Query";
import { Component, Entity, World } from "./types";
import { createWorld } from "./World";

describe("Query", () => {
let world: World;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defineComponent, removeComponent, setComponent, withValue } from "../src/Component";
import { Type, UpdateType } from "../src/constants";
import { createEntity } from "../src/Entity";
import { Has } from "../src/Query";
import { defineEnterSystem, defineExitSystem, defineSystem, defineUpdateSystem } from "../src/System";
import { Component, Entity, World } from "../src/types";
import { createWorld } from "../src/World";
import { defineComponent, removeComponent, setComponent, withValue } from "./Component";
import { Type, UpdateType } from "./constants";
import { createEntity } from "./Entity";
import { Has } from "./Query";
import { defineEnterSystem, defineExitSystem, defineSystem, defineUpdateSystem } from "./System";
import { Component, Entity, World } from "./types";
import { createWorld } from "./World";

describe("System", () => {
let world: World;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { arrayToIterator } from "@latticexyz/utils";
import { Subject } from "rxjs";
import { defineComponent, setComponent } from "../src/Component";
import { Type } from "../src/constants";
import { createEntity } from "../src/Entity";
import { World, AnyComponent, EntitySymbol } from "../src/types";
import { createWorld, getEntityComponents } from "../src/World";
import { defineComponent, setComponent } from "./Component";
import { Type } from "./constants";
import { createEntity } from "./Entity";
import { World, AnyComponent, EntitySymbol } from "./types";
import { createWorld, getEntityComponents } from "./World";

describe("World", () => {
describe("createWorld", () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/recs/src/deprecated/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum ActionState {
Requested = "Requested",
Executing = "Executing",
WaitingForTxEvents = "WaitingForTxEvents",
Complete = "Complete",
Failed = "Failed",
Cancelled = "Cancelled",
TxReduced = "TxReduced",
}
Loading

0 comments on commit 0987732

Please sign in to comment.