shinkansen-pantograph 1.1.24 → 1.2.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shinkansen-pantograph",
3
- "version": "1.1.24",
3
+ "version": "1.2.0",
4
4
  "description": "Shinkansen Pantograph",
5
5
  "keywords": [
6
6
  "Shinkansen",
@@ -40,7 +40,7 @@
40
40
  "@babel/plugin-proposal-export-default-from": "^7.18.10",
41
41
  "@babel/preset-env": "^7.21.5",
42
42
  "@babel/register": "^7.21.0",
43
- "@modernpoacher/hooks": "^1.0.398",
43
+ "@modernpoacher/hooks": "^1.0.399",
44
44
  "@typescript-eslint/eslint-plugin": "^5.59.5",
45
45
  "@typescript-eslint/parser": "^5.59.5",
46
46
  "babel-plugin-module-resolver": "^5.0.0",
@@ -66,71 +66,66 @@ const ACTION = {}
66
66
 
67
67
  const STATE = {}
68
68
 
69
- const HISTORY = {
70
- push () {},
71
- getCurrentLocation () {
72
- return {}
73
- }
74
- }
69
+ const ROUTE = {}
75
70
 
76
71
  log('`shinkansen` is awake')
77
72
 
78
- export function redirectToAlpha ({ alpha, history }) {
79
- log('redirectToAlpha')
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
- } = history.getCurrentLocation()
79
+ } = route
85
80
 
86
- if (pathname !== currentPathname) history.push(pathname)
81
+ if (pathname !== currentPathname) return pathname
87
82
  }
88
83
 
89
- export function redirectToOmega ({ alpha, omega, history }) {
90
- log('redirectToOmega')
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
- } = history.getCurrentLocation()
90
+ } = route
96
91
 
97
- if (pathname !== currentPathname) history.push(pathname)
92
+ if (pathname !== currentPathname) return pathname
98
93
  }
99
94
 
100
- export function redirectToEmbark ({ embark, history }) {
101
- log('redirectToEmbark')
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
- } = history.getCurrentLocation()
101
+ } = route
107
102
 
108
- if (pathname !== currentPathname) history.push(pathname)
103
+ if (pathname !== currentPathname) return pathname
109
104
  }
110
105
 
111
- export function redirectToDebark ({ debark, history }) {
112
- log('redirectToDebark')
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
- } = history.getCurrentLocation()
112
+ } = route
118
113
 
119
- if (pathname !== currentPathname) history.push(pathname)
114
+ if (pathname !== currentPathname) return pathname
120
115
  }
121
116
 
122
- export function redirectToConfirm ({ confirm, history }) {
123
- log('redirectToDebark')
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
- } = history.getCurrentLocation()
123
+ } = route
129
124
 
130
- if (pathname !== currentPathname) history.push(pathname)
125
+ if (pathname !== currentPathname) return pathname
131
126
  }
132
127
 
133
- export function redirectTo ({
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
- history
136
+ route
142
137
  }) {
143
- log('redirectTo')
138
+ log('getRedirectTo')
144
139
 
145
140
  if (alpha && omega) {
146
- redirectToOmega({ alpha, omega, history })
141
+ return getRedirectToOmega({ alpha, omega, route })
147
142
  } else if (embark) {
148
- redirectToEmbark({ embark, history })
143
+ return getRedirectToEmbark({ embark, route })
149
144
  } else if (debark) {
150
- redirectToDebark({ debark, history })
145
+ return getRedirectToDebark({ debark, route })
151
146
  } else if (confirm) {
152
- redirectToDebark({ confirm, history })
147
+ return getRedirectToDebark({ confirm, route })
153
148
  } else if (alpha) { // can appear on its own
154
- redirectToAlpha({ alpha, history })
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 `redirectTo()`')
151
+ throw Error('Pantograph encountered a route error in `getRedirectTo()`')
157
152
  }
158
153
  }
159
154
 
160
- export function redirectFromAlpha ({ state: { [Signals.ALPHA]: { redirect } = {} } = {}, history }) {
161
- log('redirectFromAlpha')
155
+ export function getRedirectFromAlpha ({ state: { [Signals.ALPHA]: { redirect } = {} } = {}, route }) {
156
+ log('getRedirectFromAlpha')
162
157
 
163
- if (redirect) redirectTo({ redirect, history })
158
+ if (redirect) return getRedirectTo({ redirect, route })
164
159
  }
165
160
 
166
- export function redirectFromOmega ({ state: { [Signals.OMEGA]: { redirect } = {} } = {}, history }) {
167
- log('redirectFromOmega')
161
+ export function getRedirectFromOmega ({ state: { [Signals.OMEGA]: { redirect } = {} } = {}, route }) {
162
+ log('getRedirectFromOmega')
168
163
 
169
- if (redirect) redirectTo({ redirect, history })
164
+ if (redirect) return getRedirectTo({ redirect, route })
170
165
  }
171
166
 
172
- export function redirectFromEmbark ({ state: { [Signals.EMBARK]: { redirect } = {} } = {}, history }) {
173
- log('redirectFromEmbark')
167
+ export function getRedirectFromEmbark ({ state: { [Signals.EMBARK]: { redirect } = {} } = {}, route }) {
168
+ log('getRedirectFromEmbark')
174
169
 
175
- if (redirect) redirectTo({ redirect, history })
170
+ if (redirect) return getRedirectTo({ redirect, route })
176
171
  }
177
172
 
178
- export function redirectFromDebark ({ state: { [Signals.DEBARK]: { redirect } = {} } = {}, history }) {
179
- log('redirectFromDebark')
173
+ export function getRedirectFromDebark ({ state: { [Signals.DEBARK]: { redirect } = {} } = {}, route }) {
174
+ log('getRedirectFromDebark')
180
175
 
181
- if (redirect) redirectTo({ redirect, history })
176
+ if (redirect) return getRedirectTo({ redirect, route })
182
177
  }
183
178
 
184
- export function redirectFromConfirm ({ state: { [Signals.CONFIRM]: { redirect } = {} } = {}, history }) {
185
- log('redirectFromConfirm')
179
+ export function getRedirectFromConfirm ({ state: { [Signals.CONFIRM]: { redirect } = {} } = {}, route }) {
180
+ log('getRedirectFromConfirm')
186
181
 
187
- if (redirect) redirectTo({ redirect, history })
182
+ if (redirect) return getRedirectTo({ redirect, route })
188
183
  }
189
184
 
190
- export function graphite ({ action: { type } = ACTION, state = STATE, history = HISTORY }) {
185
+ export function graphite ({ action: { type } = ACTION, state = STATE, route = ROUTE }) {
191
186
  switch (type) {
192
187
  case OMEGA.ROUTE:
193
- redirectFromOmega({ state, history })
194
- break
188
+ return getRedirectFromOmega({ state, route })
195
189
  case EMBARK.ROUTE:
196
- redirectFromEmbark({ state, history })
197
- break
190
+ return getRedirectFromEmbark({ state, route })
198
191
  case DEBARK.ROUTE:
199
- redirectFromDebark({ state, history })
200
- break
192
+ return getRedirectFromDebark({ state, route })
201
193
  case CONFIRM.ROUTE:
202
- redirectFromDebark({ state, history })
203
- break
194
+ return getRedirectFromDebark({ state, route })
204
195
  case ALPHA.ROUTE:
205
- redirectFromAlpha({ state, history })
206
- break
196
+ return getRedirectFromAlpha({ state, route })
207
197
  }
208
198
  }
209
199