ts-odd icon indicating copy to clipboard operation
ts-odd copied to clipboard

Eliminate impossible states on initialise

Open icidasset opened this issue 4 years ago • 2 comments

User feedback 💌

With the StrictNullCheck enabled in Typescript, users are required to do:

case Scenario.AuthSucceeded:
case Scenario.Continuation:
  if (state.fs != null) {
    if (state.fs.appPath != null) {
      const appPath = state.fs.appPath();
      ...
    }
  }

Ideally we would not need to do these "null" checks, but not sure how much we could eliminate these. Seeing that the presence of these things depends on the options given to initialise. state.fs can be undefined if given the loadFileSystem: false option (which one may do to load the file system themselves in a web worker), and fs.appPath can be undefined if the permissions.app option was not set.

icidasset avatar Oct 01 '20 13:10 icidasset

One option (not necessarily the right one) is only expose a FS handle if the app path is available, and hide all of the above detail. As a quick sketch:

fission.withApp("icidasset", "diffuse", app => {
  // do stuff with App here
});

or even wrap it in a promise so you get the reject:

const app = await fission.getApp({
  creator: "icidasset",
  appName: "diffuse"
}).catch(err => handleErr(err));

which may be good if it also will have to wait for the network

(That said, this is pretty seriously monadic in flavour, so it could just be that my brain is DEEP in Haskell land at present)

expede avatar Nov 24 '20 21:11 expede

state.fs can be undefined if given the loadFileSystem: false I read this and was thinking there's a solution for this:

https://github.com/fission-suite/webnative/blob/fea00981c64307b336605da024fc1b5a5708f49a/src/index.ts#L102-L121

But I think the solution is quite ugly and IMHO I don't think it's worth it. There's probably a better way to structure this API, most likely one that uses typescript's capability of depending on the actual parameter's values more effectively.

matheus23 avatar Mar 30 '21 13:03 matheus23