@picked/svelte 0.0.62-next.2 → 0.0.62-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/events.js +1 -1
- package/dist/router/StepRouter.svelte +11 -45
- package/package.json +2 -2
package/dist/hooks/events.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getExperience as e,getPicked as t}from"./client.js";import{attach as n}from"effector";import{trackRecommendationPresentEvent as r}from"@picked/analytics";var i=()=>{let{session:i,projectId:a}=t(),o=e();return n({source:{config:o.configStore,step:o.currentStepStore},async effect({config:e,step:t},
|
|
1
|
+
import{getExperience as e,getPicked as t}from"./client.js";import{attach as n}from"effector";import{trackRecommendationPresentEvent as r}from"@picked/analytics";var i=()=>{let{session:i,projectId:a}=t(),o=e();return n({source:{config:o.configStore,step:o.currentStepStore,sessionSnapshot:i.store},async effect({config:e,step:t,sessionSnapshot:n},i){if(!t)throw Error(`Cannot track recommendation present event: missing experience step.`);return r({projectId:a,experience:{id:o.experienceId,title:e.name},sessionId:n.id,identifiers:n.identifiers,isUser:n.isUser,step:t,productList:i})}})};export{i as getTrackRecommendationPresentEvent};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
/** @file Root router component that manages step registration and active step detection via Effector. */
|
|
3
|
-
import { createEvent, createStore
|
|
4
|
-
import { supportsWindow } from '@picked/client'
|
|
3
|
+
import { combine, createEvent, createStore } from 'effector'
|
|
5
4
|
import { getExperience } from '../hooks'
|
|
6
5
|
import { setStepRouter, type Step } from './context'
|
|
7
6
|
|
|
@@ -9,57 +8,24 @@
|
|
|
9
8
|
|
|
10
9
|
const { currentStepStore } = experience
|
|
11
10
|
|
|
12
|
-
const activeStepStore = createStore<Step | null>(null)
|
|
13
|
-
let hasActiveStep = false
|
|
14
11
|
const stepsStore = createStore<Step[]>([])
|
|
15
12
|
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const setActiveStepEvent = createEvent<Step | null>()
|
|
13
|
+
const registerStep = createEvent<Step>()
|
|
14
|
+
const unregisterStep = createEvent<Step>()
|
|
19
15
|
|
|
20
|
-
stepsStore
|
|
21
|
-
|
|
16
|
+
stepsStore
|
|
17
|
+
.on(registerStep, (state, step) => [...state, step])
|
|
18
|
+
.on(unregisterStep, (state, step) => state.filter((s) => s !== step))
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const registerStep = (step: Step) => {
|
|
30
|
-
// todo: getIsSSR context
|
|
31
|
-
|
|
32
|
-
if (!supportsWindow()) {
|
|
33
|
-
// In SSR we should set the activeStep immediately if it is a match.
|
|
34
|
-
// If there are more Routes being registered after a match is found,
|
|
35
|
-
// we just skip them.
|
|
36
|
-
if (hasActiveStep) return
|
|
37
|
-
|
|
38
|
-
const isMatchingStep = step.key === currentStepStore.getState()?.key
|
|
39
|
-
|
|
40
|
-
if (isMatchingStep) {
|
|
41
|
-
setActiveStepEvent(step)
|
|
42
|
-
hasActiveStep = true
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
registerStepEvent(step)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const unregisterStep = (step: Step) => {
|
|
50
|
-
unregisterStepEvent(step)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
sample({
|
|
54
|
-
source: { steps: stepsStore, currentStep: currentStepStore },
|
|
55
|
-
fn: ({ steps, currentStep }) => steps.find((s) => s.key === currentStep?.key) || null,
|
|
56
|
-
target: setActiveStepEvent,
|
|
57
|
-
})
|
|
20
|
+
const activeStepStore = combine(
|
|
21
|
+
{ steps: stepsStore, currentStep: currentStepStore },
|
|
22
|
+
({ steps, currentStep }) => steps.find((s) => s.key === currentStep?.key) ?? null,
|
|
23
|
+
)
|
|
58
24
|
|
|
59
25
|
setStepRouter({
|
|
60
26
|
registerStep,
|
|
61
27
|
unregisterStep,
|
|
62
|
-
activeStep: activeStepStore
|
|
28
|
+
activeStep: activeStepStore,
|
|
63
29
|
})
|
|
64
30
|
</script>
|
|
65
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/svelte",
|
|
3
|
-
"version": "0.0.62-next.
|
|
3
|
+
"version": "0.0.62-next.4",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"d3": "^7.9.0"
|
|
6
6
|
},
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
},
|
|
89
89
|
"module": "./dist/index.js",
|
|
90
90
|
"peerDependencies": {
|
|
91
|
-
"@picked/client": "0.0.62-next.
|
|
91
|
+
"@picked/client": "0.0.62-next.4",
|
|
92
92
|
"effector": "^23.3.0",
|
|
93
93
|
"svelte": "^5.46.4"
|
|
94
94
|
},
|