shinkansen-pantograph 1.1.25 → 1.2.1
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/package.json +3 -3
- package/src/pantograph/index.mjs +51 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shinkansen-pantograph",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Shinkansen Pantograph",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Shinkansen",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"husky": "^8.0.3",
|
|
58
58
|
"mocha": "^10.2.0",
|
|
59
59
|
"rimraf": "^5.0.0",
|
|
60
|
-
"shinkansen-rails": "1.0.
|
|
61
|
-
"shinkansen-signals": "1.1.
|
|
60
|
+
"shinkansen-rails": "1.0.41",
|
|
61
|
+
"shinkansen-signals": "1.1.24",
|
|
62
62
|
"sinon": "^15.0.4",
|
|
63
63
|
"sinon-chai": "^3.7.0"
|
|
64
64
|
},
|
package/src/pantograph/index.mjs
CHANGED
|
@@ -66,71 +66,66 @@ const ACTION = {}
|
|
|
66
66
|
|
|
67
67
|
const STATE = {}
|
|
68
68
|
|
|
69
|
-
const
|
|
70
|
-
push () {},
|
|
71
|
-
getCurrentLocation () {
|
|
72
|
-
return {}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
69
|
+
const ROUTE = {}
|
|
75
70
|
|
|
76
71
|
log('`shinkansen` is awake')
|
|
77
72
|
|
|
78
|
-
export function
|
|
79
|
-
log('
|
|
73
|
+
export function getRedirectToAlpha ({ alpha, route }) {
|
|
74
|
+
log('getRedirectToAlpha')
|
|
80
75
|
|
|
81
76
|
const pathname = Rails.to({ [Signals.ALPHA]: alpha }, Signals.ALPHA_PATTERN)
|
|
82
77
|
const {
|
|
83
78
|
pathname: currentPathname
|
|
84
|
-
} =
|
|
79
|
+
} = route
|
|
85
80
|
|
|
86
|
-
if (pathname !== currentPathname)
|
|
81
|
+
if (pathname !== currentPathname) return pathname
|
|
87
82
|
}
|
|
88
83
|
|
|
89
|
-
export function
|
|
90
|
-
log('
|
|
84
|
+
export function getRedirectToOmega ({ alpha, omega, route }) {
|
|
85
|
+
log('getRedirectToOmega')
|
|
91
86
|
|
|
92
87
|
const pathname = Rails.to({ [Signals.ALPHA]: alpha, [Signals.OMEGA]: omega }, Signals.OMEGA_PATTERN)
|
|
93
88
|
const {
|
|
94
89
|
pathname: currentPathname
|
|
95
|
-
} =
|
|
90
|
+
} = route
|
|
96
91
|
|
|
97
|
-
if (pathname !== currentPathname)
|
|
92
|
+
if (pathname !== currentPathname) return pathname
|
|
98
93
|
}
|
|
99
94
|
|
|
100
|
-
export function
|
|
101
|
-
log('
|
|
95
|
+
export function getRedirectToEmbark ({ embark, route }) {
|
|
96
|
+
log('getRedirectToEmbark')
|
|
102
97
|
|
|
103
98
|
const pathname = Rails.to({ [Signals.EMBARK]: embark }, Signals.EMBARK_PATTERN)
|
|
104
99
|
const {
|
|
105
100
|
pathname: currentPathname
|
|
106
|
-
} =
|
|
101
|
+
} = route
|
|
107
102
|
|
|
108
|
-
if (pathname !== currentPathname)
|
|
103
|
+
if (pathname !== currentPathname) return pathname
|
|
109
104
|
}
|
|
110
105
|
|
|
111
|
-
export function
|
|
112
|
-
log('
|
|
106
|
+
export function getRedirectToDebark ({ debark, route }) {
|
|
107
|
+
log('getRedirectToDebark')
|
|
113
108
|
|
|
114
109
|
const pathname = Rails.to({ [Signals.DEBARK]: debark }, Signals.DEBARK_PATTERN)
|
|
115
110
|
const {
|
|
116
111
|
pathname: currentPathname
|
|
117
|
-
} =
|
|
112
|
+
} = route
|
|
118
113
|
|
|
119
|
-
if (pathname !== currentPathname)
|
|
114
|
+
if (pathname !== currentPathname) return pathname
|
|
120
115
|
}
|
|
121
116
|
|
|
122
|
-
export function
|
|
123
|
-
log('
|
|
117
|
+
export function getRedirectToConfirm ({ confirm, route }) {
|
|
118
|
+
log('getRedirectToDebark')
|
|
124
119
|
|
|
125
120
|
const pathname = Rails.to({ [Signals.CONFIRM]: confirm }, Signals.CONFIRM_PATTERN)
|
|
126
121
|
const {
|
|
127
122
|
pathname: currentPathname
|
|
128
|
-
} =
|
|
123
|
+
} = route
|
|
129
124
|
|
|
130
|
-
if (pathname !== currentPathname)
|
|
125
|
+
if (pathname !== currentPathname) return pathname
|
|
131
126
|
}
|
|
132
127
|
|
|
133
|
-
export function
|
|
128
|
+
export function getRedirectTo ({
|
|
134
129
|
redirect: {
|
|
135
130
|
[Signals.ALPHA]: alpha,
|
|
136
131
|
[Signals.OMEGA]: omega,
|
|
@@ -138,72 +133,67 @@ export function redirectTo ({
|
|
|
138
133
|
[Signals.DEBARK]: debark,
|
|
139
134
|
[Signals.CONFIRM]: confirm
|
|
140
135
|
} = {},
|
|
141
|
-
|
|
136
|
+
route
|
|
142
137
|
}) {
|
|
143
|
-
log('
|
|
138
|
+
log('getRedirectTo')
|
|
144
139
|
|
|
145
140
|
if (alpha && omega) {
|
|
146
|
-
|
|
141
|
+
return getRedirectToOmega({ alpha, omega, route })
|
|
147
142
|
} else if (embark) {
|
|
148
|
-
|
|
143
|
+
return getRedirectToEmbark({ embark, route })
|
|
149
144
|
} else if (debark) {
|
|
150
|
-
|
|
145
|
+
return getRedirectToDebark({ debark, route })
|
|
151
146
|
} else if (confirm) {
|
|
152
|
-
|
|
147
|
+
return getRedirectToDebark({ confirm, route })
|
|
153
148
|
} else if (alpha) { // can appear on its own
|
|
154
|
-
|
|
149
|
+
return getRedirectToAlpha({ alpha, route })
|
|
155
150
|
} else if (omega) { // can not appear on its own
|
|
156
|
-
throw Error('Pantograph encountered a route error in `
|
|
151
|
+
throw Error('Pantograph encountered a route error in `getRedirectTo()`')
|
|
157
152
|
}
|
|
158
153
|
}
|
|
159
154
|
|
|
160
|
-
export function
|
|
161
|
-
log('
|
|
155
|
+
export function getRedirectFromAlpha ({ state: { [Signals.ALPHA]: { redirect } = {} } = {}, route }) {
|
|
156
|
+
log('getRedirectFromAlpha')
|
|
162
157
|
|
|
163
|
-
if (redirect)
|
|
158
|
+
if (redirect) return getRedirectTo({ redirect, route })
|
|
164
159
|
}
|
|
165
160
|
|
|
166
|
-
export function
|
|
167
|
-
log('
|
|
161
|
+
export function getRedirectFromOmega ({ state: { [Signals.OMEGA]: { redirect } = {} } = {}, route }) {
|
|
162
|
+
log('getRedirectFromOmega')
|
|
168
163
|
|
|
169
|
-
if (redirect)
|
|
164
|
+
if (redirect) return getRedirectTo({ redirect, route })
|
|
170
165
|
}
|
|
171
166
|
|
|
172
|
-
export function
|
|
173
|
-
log('
|
|
167
|
+
export function getRedirectFromEmbark ({ state: { [Signals.EMBARK]: { redirect } = {} } = {}, route }) {
|
|
168
|
+
log('getRedirectFromEmbark')
|
|
174
169
|
|
|
175
|
-
if (redirect)
|
|
170
|
+
if (redirect) return getRedirectTo({ redirect, route })
|
|
176
171
|
}
|
|
177
172
|
|
|
178
|
-
export function
|
|
179
|
-
log('
|
|
173
|
+
export function getRedirectFromDebark ({ state: { [Signals.DEBARK]: { redirect } = {} } = {}, route }) {
|
|
174
|
+
log('getRedirectFromDebark')
|
|
180
175
|
|
|
181
|
-
if (redirect)
|
|
176
|
+
if (redirect) return getRedirectTo({ redirect, route })
|
|
182
177
|
}
|
|
183
178
|
|
|
184
|
-
export function
|
|
185
|
-
log('
|
|
179
|
+
export function getRedirectFromConfirm ({ state: { [Signals.CONFIRM]: { redirect } = {} } = {}, route }) {
|
|
180
|
+
log('getRedirectFromConfirm')
|
|
186
181
|
|
|
187
|
-
if (redirect)
|
|
182
|
+
if (redirect) return getRedirectTo({ redirect, route })
|
|
188
183
|
}
|
|
189
184
|
|
|
190
|
-
export function graphite ({ action: { type } = ACTION, state = STATE,
|
|
185
|
+
export function graphite ({ action: { type } = ACTION, state = STATE, route = ROUTE }) {
|
|
191
186
|
switch (type) {
|
|
192
187
|
case OMEGA.ROUTE:
|
|
193
|
-
|
|
194
|
-
break
|
|
188
|
+
return getRedirectFromOmega({ state, route })
|
|
195
189
|
case EMBARK.ROUTE:
|
|
196
|
-
|
|
197
|
-
break
|
|
190
|
+
return getRedirectFromEmbark({ state, route })
|
|
198
191
|
case DEBARK.ROUTE:
|
|
199
|
-
|
|
200
|
-
break
|
|
192
|
+
return getRedirectFromDebark({ state, route })
|
|
201
193
|
case CONFIRM.ROUTE:
|
|
202
|
-
|
|
203
|
-
break
|
|
194
|
+
return getRedirectFromDebark({ state, route })
|
|
204
195
|
case ALPHA.ROUTE:
|
|
205
|
-
|
|
206
|
-
break
|
|
196
|
+
return getRedirectFromAlpha({ state, route })
|
|
207
197
|
}
|
|
208
198
|
}
|
|
209
199
|
|