nos / create-nos-dapp

CLI tool to generate a new nOS dApp
53 stars 35 forks source link

feat(nos): fallback #3

Closed jeroenptrs closed 6 years ago

DalderupMaurice commented 6 years ago

Wouldn't it make more sense to create an option (nos.setFallback) and pass a function to it, instead of passing a function to every other class? 😄

jeroenptrs commented 6 years ago

@DalderupMaurice If we can do something like this:

const nos = window.NOS && window.NOS.V1 ? window.NOS.V1 : {};
const exists = !!window.NOS && !!window.NOS.V1;
const setFallback = fallback => ({ ...fallback });

const nosFunctions = {
  exists,
  getAddress: () => exists ? nos.getAddress() : fallback.getAddress(),
  // Rest of the functions
}

export { setFallback, nosFunctions }
DalderupMaurice commented 6 years ago

Yeah looks good! If you can be sure that the fallback does contain getAddress etc :P

jeroenptrs commented 6 years ago

Yeah if we externalize this to a different package I'm gonna add error handling in as well.

jeroenptrs commented 6 years ago

Because I don't think most of this will be added in, but sent to a different package and then imported in the starter kit. Just waiting on some @mhuggins feedback as well before I move this to a new repo

jeroenptrs commented 6 years ago

Also I forgot to split the fallback object and setting the fallback, this would have to be done something like this:

const fallback = {};
const setFallback = fb => {
  for (const func in fb) {
    fallback[func] = fb[func];
  };
};
DalderupMaurice commented 6 years ago

What's the status of this?

jeroenptrs commented 6 years ago

@DalderupMaurice unnecessary, closing now. But please keep the branch up until the npm package has been published 😂