stuartsierra/component

constructor documentation question

AndreaCrotti opened this issue · 3 comments

I'm going through the README to try to learn how to use this library and I have a couple of issues..

In the docs it's written:

Optionally, provide a constructor function that takes arguments for the essential configuration parameters of the component, leaving the runtime state blank.

(defn new-database [host port](map->Database {:host host :port port}))

But

  1. what is "map->Database"?
    Just copying and pasting that with the rest of the source would not work.
  2. it says that this constructor is optional, however just below it uses it to construct the system.
    So probably for this just an extra comment would do, once it's actually clear how to define the constructor first..

Thanks a lot for the great work anyway!

Argh just realised that in fact it works, I was just using a wrong name, but where is that coming from?
The doc is not so helpful:

learn-component.core/map->MainComponent
([m__6287__auto__])
  Factory function for class learn_component.core.MainComponent, taking a map of keywords to field values.

From the defrecord doc:

Given (defrecord TypeName ...), two factory functions will be
defined: ->TypeName, taking positional parameters for the fields,
and map->TypeName, taking a map of keywords to field values.

This is how the -> functions get materialized.

Ah ok perfect thanks @ddossot
I can close this then, the slight confusion with the "optional" part remains but I'll do a PR if I find a better way..