lundi 24 août 2020

RXJS and typescript: Conditionally executing work with Server and Client Code



My requirement is to provide a function that uses various conditions to determine whether an object can be edited.
These conditions can be on both the server and the client side.
Some of these conditions should abort the execution of further validation and return the value.

i will try to make the process understandable with pseudo code.
Perhaps there is already a pattern for implementing such tasks.

isEditable(): Observable<boolean> {
  return serverSideCondition.pipe(
    switchMap(editable => {
      if (editable)
      {
        return clientSideCondition;
      }

      return of(false); // Should abort furhter conditions ...
    }),
    switchMap(editable => {
      if (editable)
      {
        return clientSideAskTheUser;
      }

      return of(false); // Should abort furhter conditions ...
    })
  );
}

Thanks

Aucun commentaire:

Enregistrer un commentaire