Skip to content

Instantly share code, notes, and snippets.

@dtex
Last active February 26, 2019 06:31
Show Gist options
  • Save dtex/addb1523dac8a1419632eeb38af42bb8 to your computer and use it in GitHub Desktop.
Save dtex/addb1523dac8a1419632eeb38af42bb8 to your computer and use it in GitHub Desktop.
Built-in vs. External providers

Built-in vs. External providers

There are advantages to the proposed external provider pattern that the built-in pattern does not enjoy. The external provider allows for:

  • Configuration on instantiation - Everything in node land needs configuration on instantiation, and I imagine there are devices where "builtin" would be the assumed pattern, but also need to be configured (i.e. wi-fi or oscillator settings)
  • Capability checks by pin - A pin map in the provider instance, which could be an object or a tiny, 1 byte-per-pin array, can describe what each pin is capable of so users don't ask a pin to do something it can't (i.e. Perhaps not all pins will have a timer for PWM)
  • Pin management - With a provider instance, it is simple to track and guard against things like using a single pin twice

An implementor may simply choose to use the external provider pattern if they have any of those needs, but conversely we could simplify things by not having the built-in pattern at all. Simple is good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment