-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript Examples? #135
Comments
I'll flag this as help wanted, maybe some of the folks using Typescript could volunteer some examples. |
I've been still working with it and thank I could possibly help provide examples if that is desired? Just point me to the best way to provide them and you can decide if they are helpful. |
Hey @jeffbski any update on this or ways that I can contribute examples? I want to help out as I love using this library over the others out there! |
Almost one year later, there are still no typescript examples. I have troubles with action payload in |
Got an extremely narrow and whacky solution right now with the latest commits from alvis... it might be that my action types definition is incompatible with redux-logic. :/ I do follow the official redux typescript docs though... and create my actions as follows: // types.ts
import { Action } from 'redux';
// […]
export const DEVICE_CONNECT_REQUEST = 'DEVICE_CONNECT_REQUEST';
// […]
interface DeviceConnectAction extends Action {
type: typeof DEVICE_CONNECT_REQUEST;
payload: {
idVendor: number | string;
idProduct: number | string;
};
}
// […]
export type DeviceConnectionType =
| DeviceConnectAction
| ... and // logic.ts
import * as types from './types';
// helper
type ActionExtractor<C> = Extract<types.DeviceConnectionType, { type: C }>;
type T = T_CONNECT | T_DISCONNECT;
type P = P_CONNECT | P_DISCONNECT;
type T_CONNECT = ActionExtractor<typeof types.DEVICE_CONNECT_REQUEST>['type'];
type P_CONNECT = ActionExtractor<typeof types.DEVICE_CONNECT_REQUEST>['payload'];
const deviceConnectLogic = createLogic<{}, { action: Action<T, P> }>({
type: types.DEVICE_CONNECT_REQUEST,
cancelType: types.DEVICE_CONNECT_CANCEL,
latest: true,
process(
{ action }: { action: Action<T_CONNECT, P_CONNECT> },
dispatch: (connectAction: types.DeviceDisConnectType) => void,
done: () => void,
) {
// we need to cast the payload type here because we did not extend Action from redux-logic here
const { idVendor, idProduct } = <P_CONNECT>action.payload;
// tell the service to connect device with { idVendor, idProduct }
DeviceService.connectDevice(idVendor, idProduct)
.then(() => {
dispatch(connectDeviceSuccess());
})
.catch((reason: string) => {
dispatch(connectDeviceFailure(reason));
})
.finally(() => {
done();
});
},
});
// Disconnect code analogous to the Connect code I'll try to investigate further and as soon as I'm ready to publish my repo with redux-logic ts code, I'll link it here. |
Thanks @tahesse that will be very helpful. |
@tahesse any updates on this? |
@TobiasPr I am still at it but had major delays because there was too much stress with other things. Thanks for pinging me, I'll pick up the issue (once again) and report my findings (in whatever form that might be). EDIT 1 Sorry, my electron code base is currently broken and I need to fix it first before I can continue to test this and provide you guys with an "how I did it" code example. EDIT 2 Might take a while... my harfbuzz lib is too new (I'm using arch btw 😛) for electron and my whole code runs in the electron app... waiting for them to recompile towards the newest harfbuzz so... |
Here's a solution for redux-logic 3.0.3, using Redux Toolkit's action creators. Given an action creator like this: export const uploadData = createAction<{ alwaysNotify?: boolean }>('uploadData'); The redux-logic handler should be able to access the payload like this: export const uploadRunsLogic = createLogic<RootState, ReturnType<typeof uploadData>['payload']>({
type: uploadData.type,
latest: true,
async process({ getState, action }, dispatch, done) {
const { alwaysNotify } = action.payload; |
I'm starting to use Typescript in a project and I've used Redux-logic in pretty much all my previous projects. With Typescript though it's been a challenge. I haven't seen that many examples, so I was wondering if there are some can we get them into the docs?
I've only seen one example which isn't even the simplest case. I'm going to keep trying to figure out how it wants things structured in the meantime and make a PR with some examples if its cool.
The text was updated successfully, but these errors were encountered: