farmOS / farmOS.js

A JavaScript library for working with farmOS data structures and interacting with farmOS servers.
MIT License
17 stars 13 forks source link

Unnest remote options in main config #49

Closed jgaehring closed 3 years ago

jgaehring commented 3 years ago

When the main factory function, farmOS, is called to instantiate the model and client, it gets a config object that contains remote.options:

https://github.com/farmOS/farmOS.js/blob/c5506ef913dfaee3a61a8e50eb9874920d9c52fe/src/index.js#L8-L18

I did this largely because I didn't want to be opinionated about the type of options that were supplied, since they will depend entirely on the adapter being used. For example, the only options being passed right now are the host and clientId, but there could easily be options that don't use the clientId for OAuth, and I can even see where p2p implementations might not even use a dedicated host.

A much better way of accommodating these options w/o being opinionated would be to use spread syntax:

  const {
    schemata = {},
    remote: {
      adapter = d9JsonApiAdapter,
      ...options
    } = {},
  } = config;

This is such a simple, tiny change, but it will still be a major, breaking change, so best to do this now, before it's too pervasive. It will make for a much cleaner API, so I don't have to continually nest options, which I'm realizing is quite a PITA:

const farm = farmOS({
  remote: { options: { host, clientId } },
});