-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: Remove _TYPE suffix from actionTypes (#3244)
- Loading branch information
Showing
37 changed files
with
267 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@data-client/test': patch | ||
--- | ||
|
||
Support [actionTypes](https://dataclient.io/docs/api/Actions) without \_TYPE suffix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
'@data-client/react': patch | ||
'@data-client/core': patch | ||
--- | ||
|
||
Add [actionTypes](https://dataclient.io/docs/api/Actions) without \_TYPE suffix | ||
|
||
(Not breaking - we keep the old actionTypes name as well.) | ||
|
||
```ts title="Before" | ||
import type { Manager, Middleware } from '@data-client/react'; | ||
import { actionTypes } from '@data-client/react'; | ||
|
||
export default class LoggingManager implements Manager { | ||
middleware: Middleware = controller => next => async action => { | ||
switch (action.type) { | ||
case actionTypes.SET_RESPONSE_TYPE: | ||
console.info( | ||
`${action.endpoint.name} ${JSON.stringify(action.response)}`, | ||
); | ||
default: | ||
return next(action); | ||
} | ||
}; | ||
|
||
cleanup() {} | ||
} | ||
``` | ||
|
||
```ts title="After" | ||
import type { Manager, Middleware } from '@data-client/react'; | ||
import { actionTypes } from '@data-client/react'; | ||
|
||
export default class LoggingManager implements Manager { | ||
middleware: Middleware = controller => next => async action => { | ||
switch (action.type) { | ||
case actionTypes.SET_RESPONSE: | ||
console.info( | ||
`${action.endpoint.name} ${JSON.stringify(action.response)}`, | ||
); | ||
default: | ||
return next(action); | ||
} | ||
}; | ||
|
||
cleanup() {} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
export const FETCH_TYPE = 'rdc/fetch' as const; | ||
export const SET_TYPE = 'rdc/set' as const; | ||
export const SET_RESPONSE_TYPE = 'rdc/setresponse' as const; | ||
export const OPTIMISTIC_TYPE = 'rdc/optimistic' as const; | ||
export const RESET_TYPE = 'rdc/reset' as const; | ||
export const SUBSCRIBE_TYPE = 'rdc/subscribe' as const; | ||
export const UNSUBSCRIBE_TYPE = 'rdc/unsubscribe' as const; | ||
export const INVALIDATE_TYPE = 'rdc/invalidate' as const; | ||
export const INVALIDATEALL_TYPE = 'rdc/invalidateall' as const; | ||
export const EXPIREALL_TYPE = 'rdc/expireall' as const; | ||
export const GC_TYPE = 'rdc/gc' as const; | ||
export const FETCH = 'rdc/fetch' as const; | ||
export const SET = 'rdc/set' as const; | ||
export const SET_RESPONSE = 'rdc/setresponse' as const; | ||
export const OPTIMISTIC = 'rdc/optimistic' as const; | ||
export const RESET = 'rdc/reset' as const; | ||
export const SUBSCRIBE = 'rdc/subscribe' as const; | ||
export const UNSUBSCRIBE = 'rdc/unsubscribe' as const; | ||
export const INVALIDATE = 'rdc/invalidate' as const; | ||
export const INVALIDATEALL = 'rdc/invalidateall' as const; | ||
export const EXPIREALL = 'rdc/expireall' as const; | ||
export const GC = 'rdc/gc' as const; | ||
|
||
export const FETCH_TYPE = FETCH; | ||
export const SET_TYPE = SET; | ||
export const SET_RESPONSE_TYPE = SET_RESPONSE; | ||
export const OPTIMISTIC_TYPE = OPTIMISTIC; | ||
export const RESET_TYPE = RESET; | ||
export const SUBSCRIBE_TYPE = SUBSCRIBE; | ||
export const UNSUBSCRIBE_TYPE = UNSUBSCRIBE; | ||
export const INVALIDATE_TYPE = INVALIDATE; | ||
export const INVALIDATEALL_TYPE = INVALIDATEALL; | ||
export const EXPIREALL_TYPE = EXPIREALL; | ||
export const GC_TYPE = GC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { EXPIREALL_TYPE } from '../../actionTypes.js'; | ||
import { EXPIREALL } from '../../actionTypes.js'; | ||
import type { ExpireAllAction } from '../../types.js'; | ||
|
||
export function createExpireAll( | ||
testKey: (key: string) => boolean, | ||
): ExpireAllAction { | ||
return { | ||
type: EXPIREALL_TYPE, | ||
type: EXPIREALL, | ||
testKey, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import type { EndpointInterface } from '@data-client/normalizr'; | ||
|
||
import { INVALIDATE_TYPE } from '../../actionTypes.js'; | ||
import { INVALIDATE } from '../../actionTypes.js'; | ||
import type { InvalidateAction } from '../../types.js'; | ||
|
||
export function createInvalidate<E extends EndpointInterface>( | ||
endpoint: E, | ||
{ args }: { args: readonly [...Parameters<E>] }, | ||
): InvalidateAction { | ||
return { | ||
type: INVALIDATE_TYPE, | ||
type: INVALIDATE, | ||
key: endpoint.key(...args), | ||
}; | ||
} |
Oops, something went wrong.