Skip to content

Commit

Permalink
fix: startFlow by location
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVidra committed Jan 6, 2024
1 parent fc736a3 commit 33216a4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ npm install @rbnd/flows
### Via CDN

```html
<script src="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.26/dist/index.global.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.26/public/flows.css" />
<script src="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.27/dist/index.global.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.27/public/flows.css" />
```

### Usage
Expand Down
4 changes: 2 additions & 2 deletions examples/vanilla-js/cloud/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<title>Cloud</title>

<!-- How you would use Flows in your own code -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.26/dist/index.global.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.27/dist/index.global.js"></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.26/public/flows.css"
href="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.27/public/flows.css"
/> -->

<!-- Development scripts -->
Expand Down
4 changes: 2 additions & 2 deletions examples/vanilla-js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<title>Vanilla JS example - Flows JS</title>

<!-- How you would use Flows in your own code -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.26/dist/index.global.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.27/dist/index.global.js"></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.26/public/flows.css"
href="https://cdn.jsdelivr.net/npm/@rbnd/flows@0.0.27/public/flows.css"
/> -->

<!-- Development scripts -->
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rbnd/flows",
"version": "0.0.26",
"version": "0.0.27",
"description": "A better way to onboard users and drive product adoption.",
"repository": {
"type": "git",
Expand Down
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@ import type {
FlowsOptions,
StartFlowOptions,
TrackingEvent,
FlowTooltipStep,
FlowModalStep,
FlowWaitStep,
} from "./types";
import { isValidFlow, isValidFlowsOptions, validateFlow, validateFlowsOptions } from "./validation";
import { init as _init } from "./init";

export * from "./public-methods";
export const init: (options: FlowsOptions) => void = _init;
export { isValidFlow, isValidFlowsOptions, validateFlow, validateFlowsOptions };
export type { Flow, FlowStep, FlowSteps, FlowsOptions, StartFlowOptions, TrackingEvent };
export type {
Flow,
FlowStep,
FlowSteps,
FlowsOptions,
StartFlowOptions,
TrackingEvent,
FlowTooltipStep,
FlowModalStep,
FlowWaitStep,
};
15 changes: 5 additions & 10 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import { validateFlowsOptions } from "./validation";
let observer: MutationObserver | null = null;

export const init = (options: FlowsInitOptions): void => {
setTimeout(() => {
_init(options);
}, 0);
};
const _init = (options: FlowsInitOptions): void => {
const validationResult = validateFlowsOptions(options);
if (validationResult.error)
log.error(
Expand Down Expand Up @@ -146,11 +141,6 @@ const _init = (options: FlowsInitOptions): void => {
if (locationChanged) {
options.onLocationChange?.(pathname, FlowsContext.getInstance());

Object.values(context.flowsById ?? {}).forEach((flow) => {
if (!flow.location) return;
if (locationMatch({ location: flow.location, pathname })) startFlow(flow.id);
});

FlowsContext.getInstance().instances.forEach((state) => {
const step = state.currentStep;
if (!step) return;
Expand All @@ -173,6 +163,11 @@ const _init = (options: FlowsInitOptions): void => {
}
}
});

Object.values(context.flowsById ?? {}).forEach((flow) => {
if (!flow.location) return;
if (locationMatch({ location: flow.location, pathname })) startFlow(flow.id);
});
}
prevPathname = pathname;

Expand Down

0 comments on commit 33216a4

Please sign in to comment.