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

feat(core,react): add targetActivityId property #502

Merged
merged 4 commits into from
Aug 14, 2024
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
6 changes: 6 additions & 0 deletions .changeset/light-dragons-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@stackflow/react": minor
"@stackflow/core": minor
---

feat(core,react): add `targetActivityId` option
28 changes: 28 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"mode": "exit",
"tag": "canary",
"initialVersions": {
"@stackflow/config": "1.1.0",
"@stackflow/core": "1.1.0-canary.0",
"@stackflow/demo": "1.3.1-canary.0",
"@stackflow/docs": "1.2.26-canary.0",
"@stackflow/compat-await-push": "1.1.12-canary.0",
"@stackflow/link": "1.4.4-canary.0",
"@stackflow/plugin-basic-ui": "1.9.1-canary.0",
"@stackflow/plugin-devtools": "0.1.11-canary.0",
"@stackflow/plugin-google-analytics-4": "1.1.14-canary.0",
"@stackflow/plugin-history-sync": "1.6.2-canary.0",
"@stackflow/plugin-map-initial-activity": "1.0.10-canary.0",
"@stackflow/plugin-preload": "1.4.1-canary.0",
"@stackflow/plugin-renderer-basic": "1.1.12-canary.0",
"@stackflow/plugin-renderer-web": "1.1.12-canary.0",
"@stackflow/plugin-stack-depth-change": "1.1.5-canary.0",
"@stackflow/react-ui-core": "1.1.1-canary.0",
"@stackflow/react": "1.3.0-canary.0",
"@stackflow/esbuild-config": "1.0.3"
},
"changesets": [
"light-dragons-bow",
"silly-doors-eat"
]
}
5 changes: 5 additions & 0 deletions .changeset/silly-doors-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stackflow/react": patch
---

feat(react): add `targetActivityId` param for future api
6 changes: 6 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @stackflow/core

## 1.1.0-canary.0

### Minor Changes

- feat(core,react): add `targetActivityId` option

## 1.0.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stackflow/core",
"version": "1.0.14",
"version": "1.1.0-canary.0",
"repository": {
"type": "git",
"url": "https://github.com/daangn/stackflow.git",
Expand Down
12 changes: 12 additions & 0 deletions core/src/activity-utils/findTargetActivityIndexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export default function findTargetActivityIndexes(
const latestActivity = findLatestActiveActivity(activities);

if (latestActivity) {
if (
event.targetActivityId &&
event.targetActivityId !== latestActivity.id
) {
break;
}
targetActivities.push(activities.indexOf(latestActivity));
}
break;
Expand All @@ -82,6 +88,12 @@ export default function findTargetActivityIndexes(
const latestActivity = findLatestActiveActivity(activities);

if (latestActivity && latestActivity.steps.length > 1) {
if (
event.targetActivityId &&
event.targetActivityId !== latestActivity.id
) {
break;
}
targetActivities.push(activities.indexOf(latestActivity));
}

Expand Down
85 changes: 85 additions & 0 deletions core/src/aggregate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3846,3 +3846,88 @@ test("aggregate - After Push > Push > Pop > Replace, first pushed activity shoul
globalTransitionState: "idle",
});
});

test("aggregate - StepPushedEvent must be ignored when top activity is not target activity", () => {
const t = nowTime();

let pushedEvent1: PushedEvent;
let pushedEvent2: PushedEvent;
let stepPushedEvent: StepPushedEvent;

const events = [
initializedEvent({
transitionDuration: 300,
}),
registeredEvent({
activityName: "sample",
}),
(pushedEvent1 = makeEvent("Pushed", {
activityId: "A",
activityName: "sample",
activityParams: {},
eventDate: enoughPastTime(),
})),
(pushedEvent2 = makeEvent("Pushed", {
activityId: "B",
activityName: "sample",
activityParams: {},
eventDate: enoughPastTime(),
})),
(stepPushedEvent = makeEvent("StepPushed", {
stepId: "s1",
stepParams: {},
targetActivityId: pushedEvent1.activityId,
eventDate: enoughPastTime(),
})),
];

const output = aggregate(events, t + 300);

expect(output).toStrictEqual({
activities: [
activity({
id: "A",
name: "sample",
transitionState: "enter-done",
params: {},
steps: [
{
id: "A",
params: {},
enteredBy: pushedEvent1,
},
],
enteredBy: pushedEvent1,
isActive: false,
isTop: false,
isRoot: true,
zIndex: 0,
}),
activity({
id: "B",
name: "sample",
transitionState: "enter-done",
params: {},
steps: [
{
id: "B",
params: {},
enteredBy: pushedEvent2,
},
],
enteredBy: pushedEvent2,
isActive: true,
isTop: true,
isRoot: false,
zIndex: 1,
}),
],
registeredActivities: [
{
name: "sample",
},
],
transitionDuration: 300,
globalTransitionState: "idle",
});
});
7 changes: 6 additions & 1 deletion core/src/event-types/StepPoppedEvent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import type { BaseDomainEvent } from "./_base";

export type StepPoppedEvent = BaseDomainEvent<"StepPopped", {}>;
export type StepPoppedEvent = BaseDomainEvent<
"StepPopped",
{
targetActivityId?: string;
}
>;
1 change: 1 addition & 0 deletions core/src/event-types/StepPushedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export type StepPushedEvent = BaseDomainEvent<
stepParams: {
[key: string]: string | undefined;
};
targetActivityId?: string;
}
>;
1 change: 1 addition & 0 deletions core/src/event-types/StepReplacedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export type StepReplacedEvent = BaseDomainEvent<
stepParams: {
[key: string]: string | undefined;
};
targetActivityId?: string;
}
>;
17 changes: 17 additions & 0 deletions demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @stackflow/demo

## 1.3.1-canary.0

### Patch Changes

- Updated dependencies
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]

## 1.3.0

### Minor Changes
Expand Down
24 changes: 12 additions & 12 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stackflow/demo",
"version": "1.3.0",
"version": "1.3.1-canary.0",
"private": true,
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -32,18 +32,18 @@
"dependencies": {
"@seed-design/design-token": "^1.0.3",
"@seed-design/stylesheet": "^1.0.4",
"@stackflow/compat-await-push": "^1.1.11",
"@stackflow/compat-await-push": "^1.1.12-canary.0",
"@stackflow/config": "^1.1.0",
"@stackflow/core": "^1.0.13",
"@stackflow/link": "^1.4.3",
"@stackflow/plugin-basic-ui": "^1.8.3",
"@stackflow/plugin-devtools": "^0.1.10",
"@stackflow/plugin-history-sync": "^1.6.0",
"@stackflow/plugin-map-initial-activity": "^1.0.9",
"@stackflow/plugin-preload": "^1.3.3",
"@stackflow/plugin-renderer-basic": "^1.1.11",
"@stackflow/plugin-stack-depth-change": "^1.1.4",
"@stackflow/react": "^1.2.0",
"@stackflow/core": "^1.1.0-canary.0",
"@stackflow/link": "^1.4.4-canary.0",
"@stackflow/plugin-basic-ui": "^1.9.1-canary.0",
"@stackflow/plugin-devtools": "^0.1.11-canary.0",
"@stackflow/plugin-history-sync": "^1.6.2-canary.0",
"@stackflow/plugin-map-initial-activity": "^1.0.10-canary.0",
"@stackflow/plugin-preload": "^1.4.1-canary.0",
"@stackflow/plugin-renderer-basic": "^1.1.12-canary.0",
"@stackflow/plugin-stack-depth-change": "^1.1.5-canary.0",
"@stackflow/react": "^1.3.0-canary.0",
"lorem-ipsum": "^2.0.8",
"lz-string": "^1.5.0",
"normalize.css": "^8.0.1",
Expand Down
12 changes: 12 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @stackflow/docs

## 1.2.26-canary.0

### Patch Changes

- Updated dependencies
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]

## 1.2.25

### Patch Changes
Expand Down
14 changes: 7 additions & 7 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stackflow/docs",
"version": "1.2.25",
"version": "1.2.26-canary.0",
"private": true,
"description": "Mobile-first stack navigator framework with Composable Plugin System",
"license": "MIT",
Expand All @@ -11,12 +11,12 @@
},
"dependencies": {
"@mdx-js/react": "^3.0.1",
"@stackflow/core": "^1.0.13",
"@stackflow/demo": "^1.3.0",
"@stackflow/plugin-basic-ui": "^1.8.3",
"@stackflow/plugin-history-sync": "^1.6.0",
"@stackflow/plugin-renderer-basic": "^1.1.11",
"@stackflow/react": "^1.2.0",
"@stackflow/core": "^1.1.0-canary.0",
"@stackflow/demo": "^1.3.1-canary.0",
"@stackflow/plugin-basic-ui": "^1.9.1-canary.0",
"@stackflow/plugin-history-sync": "^1.6.2-canary.0",
"@stackflow/plugin-renderer-basic": "^1.1.12-canary.0",
"@stackflow/react": "^1.3.0-canary.0",
"@types/react": "^18.3.3",
"next": "^14.2.4",
"nextra": "^2.13.4",
Expand Down
8 changes: 8 additions & 0 deletions extensions/compat-await-push/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @stackflow/compat-await-push

## 1.1.12-canary.0

### Patch Changes

- Updated dependencies
- @stackflow/[email protected]
- @stackflow/[email protected]

## 1.1.11

## 1.1.11-canary.0
Expand Down
10 changes: 5 additions & 5 deletions extensions/compat-await-push/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stackflow/compat-await-push",
"version": "1.1.11",
"version": "1.1.12-canary.0",
"repository": {
"type": "git",
"url": "https://github.com/daangn/stackflow.git",
Expand Down Expand Up @@ -31,18 +31,18 @@
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@stackflow/core": "^1.0.13",
"@stackflow/core": "^1.1.0-canary.0",
"@stackflow/esbuild-config": "^1.0.3",
"@stackflow/react": "^1.2.0",
"@stackflow/react": "^1.3.0-canary.0",
"@types/react": "^18.3.3",
"esbuild": "^0.23.0",
"react": "^18.3.1",
"rimraf": "^3.0.2",
"typescript": "^5.5.3"
},
"peerDependencies": {
"@stackflow/core": "^1",
"@stackflow/react": "^1.2.0-canary.0",
"@stackflow/core": "^1.1.0-canary.0",
"@stackflow/react": "^1.3.0-canary.0",
"@types/react": ">=16.8.0",
"react": ">=16.8.0"
},
Expand Down
10 changes: 10 additions & 0 deletions extensions/link/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @stackflow/link

## 1.4.4-canary.0

### Patch Changes

- Updated dependencies
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]
- @stackflow/[email protected]

## 1.4.3

## 1.4.3-canary.0
Expand Down
Loading
Loading