Open christianallred opened 5 years ago
An honest question. I don't think either @svrcekmichal nor I use this library anymore. Totally willing to allow others to come on and help. I think it was built as a simple utility and it works well for what it does.
No, you think we can use it for projects or not ? if it's not maintened, there will be deprecated dependencies... This middleware was SO cool, i dont understand why there no other repo doing this same feature. It was really clear and easy to use. Auto dispatch on success and error was cool. I'll try do it with axios only. Or maybe someone knows an alternative ? plz @svrcekmichal come back =D
Hi @svrcekmichal , this library has really been very useful to me. I would like to collaborate if possible, either to improve documentation or to add types. Please come back!
It seems that at this point, the best way forward is to fork it and release it under a new name (with acknowledgment of course). So far, we haven't found a breaking change that we couldn't solve on the client side. But if that happens, we'll definitely be forking and fixing the issue as we have thousands of actions that conform to this API. Missing types are a pain, but it really matters mainly in the config which you rarely touch IMHO. Btw, if you look at the size of the lib, it's not like it would be too much work to replicate the functionality one way or another.
Did anyone do this yet? It would be great to have more examples, especially how to do typing around this.
Maybe you will find this helpful, we're happy with it.
import { AnyAction } from 'redux';
abstract class Action implements AnyAction {
public type: string;
// tslint:disable-next-line: variable-name
public __proto__?: Action;
constructor() {
this.type = this.__proto__?.type || this.type;
}
}
export interface ActionClass<T extends Action> {
prototype: T;
}
export function typeName(
name: string
): <T extends Action>(actionClass: ActionClass<T>) => void {
return actionClass => {
// Although we could determine the type name using actionClass.prototype.constructor.name,
// it's dangerous to do that because minifiers may interfere with it, and then serialized state
// might not have the expected meaning after a recompile. So we explicitly ask for a name string.
actionClass.prototype.type = name;
};
}
export function isActionType<T extends Action>(
action: Action,
actionClass: ActionClass<T>
): action is T {
return action.type === actionClass.prototype.type;
}
// Then you define actions like this:
@typeName('SAVE_SOME_STATE')
export class SaveSomeState extends Action {
constructor(public someValue: boolean) {
super();
}
}
// Reducer works like this:
export interface State {
someValue: boolean;
}
const initialState: State = {
someValue: false,
};
export const reducer: Reducer<State> = (state, action): State => {
if (isActionType(action, SaveSomeState )) {
return Object.assign({}, state, {
someValue: action.someValue,
} as State);
}
// For unrecognized actions (or in cases where actions have no effect), must return the existing state
// (or default initial state if none was supplied)
return state || initialState;
};
There's some more stuff around action creators (and thunk), but that could depend on your implementation, at least it does in our case. Especially based on how you do authorization, notifications, stuff like that.
Hey there are 6 pull requests and 19 open issues that have never had responses from the author.
Is there no planned support for this repo?