Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api/init should call gn/reset-notes #33

Open
behrica opened this issue Dec 2, 2020 · 5 comments
Open

api/init should call gn/reset-notes #33

behrica opened this issue Dec 2, 2020 · 5 comments

Comments

@behrica
Copy link
Member

behrica commented Dec 2, 2020

I cannot see the need to "init" the notespace, without wanting to "clean" the browser.

@behrica
Copy link
Member Author

behrica commented Dec 2, 2020

Hmm.
I get some dead-locks combining api/init and gn/reset-notes

Maybe not that simple.

@daslu
Copy link
Member

daslu commented Dec 2, 2020

notespace.api/init,
which is actually notespace.lifecycle/init,
calls notespace.renderers.gorilla-notes/init,
which calls gorilla-notes.core/reset-notes!.

@behrica
Copy link
Member Author

behrica commented Dec 3, 2020

I am maybe confused, what api/init is supposed to do.

Maybe I miss a "reset" function on api level.
Which should

  • "reset" the note-list too initial stage
  • re-read the clj file
  • clear the browser

So that a following "evaluate-notespace" starts as much "from scratch" as possible.

@behrica behrica closed this as completed Dec 3, 2020
@behrica behrica reopened this Dec 3, 2020
@daslu
Copy link
Member

daslu commented Dec 3, 2020

notespace.api/init,
which is actually notespace.lifecycle/init,
does the following things:

(defn init [& {:keys [open-browser?]

(1) resets the Notespace state, except for the config (so if the user has redefined the config, this part stays redefined)
(2) resets the renderer (which is based on Gorilla-Notes)
(3) makes sure the renderer is mount (exactly once) to reflect the system state changes

Step (1) makes sure the system information about notes is emptied. In order to fill it back, we need to ask it to evaluate namespaces, etc.

Step (2) is calling the init function of the renderer (based on Gorilla-Notes):

  • It makes sure that the Gorilla-Notes server is set (serving a page and talking with it through websockets).
  • Makes sure its list of notes is empty.
  • Sets some options.
  • Watches inputs (this is not in use at the moment).
    The browser view is reflecting the list of notes of the Gorilla-Notes renderer, all the time. So emptying this list empties the view.
    The list will start filling again when the renderer reacts to changes in Notespace.

So, of the tasks you mentioned

  • "reset" the note-list too initial stage
  • re-read the clj file
  • clear the browser

.. the only one which does not happen here is re-read the clj file. But that will happen anyway when we evaluate the namespace through the notespace api -- because it is called in this function:

(defn act-on-notes! [anamespace actions]

Does it makes sense?

@daslu
Copy link
Member

daslu commented Dec 3, 2020

Maybe the confusing thing here is that there are two states here:

  • The Notespace state.
  • The Gorilla-Notes state.

The Notespace state is managed through the Cljfx events and context system.
https://github.com/cljfx/cljfx#subscriptions-and-contexts
It contains, for example, the user config, and also the vector of notes per namespace, with all their metadata and evaluation results, etc.

The Gorilla-Notes state is just the list of hiccup elements that should appear in the browser at a given point in time.
(My apology: it is confusing that Gorilla-Notes called these hiccup elements "notes", while they are nothing but (extended) hiccup data structures, a much simpler notion than Notespace Notes.)
This state is updated by the renderer, which is a function in Notespace.

(defn renderer [old-ctx new-ctx]

This function's responsibility is to interpret the Notespace state and decide how to update the Gorilla-Notes state (that is, the list of hiccup elements).

Does it make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants