quarrant / mobx-persist-store

Persist and rehydrate observable properties in mobx store.
268 stars 14 forks source link

isFunction handles additional situations #104

Closed jwoyame closed 1 year ago

jwoyame commented 1 year ago

The current isFunction implementation is:

export const isFunction = (functionToCheck: any): boolean => {
  return functionToCheck && functionToCheck instanceof Function;
};

This PR changes it to use typeof:

export const isFunction = (functionToCheck: any): boolean => {
  return functionToCheck && typeof functionToCheck === 'function';
};

This is the implementation advised by the jQuery team.

The current isFunction will produce incorrect values for some stores. For example, the AsyncStorage mock module will incorrectly show that it is missing functions:

      mobx-persist-store: Profile does not have a valid storage adaptor.

      * Make sure the storage controller has 'getItem', 'setItem' and 'removeItem' methods."

This may be the cause of #96 as well.

codeBelt commented 1 year ago

Looks good to me. I haven't tried it out. We could just get ride of that warning if this doesn't fix it.

jwoyame commented 1 year ago

I definitely appreciate the intent of the warning. It could save a lot of hassle if you actually are using an incompatible store.