hotwire-django / turbo-django

Unmaintained // An early stage integration of Hotwire Turbo with Django
https://discuss.hotwire.dev/t/django-backend-support-for-hotwire/1570/
Other
385 stars 20 forks source link

Docs should be better. #73

Open nerdoc opened 2 years ago

nerdoc commented 2 years ago

I can't get turbo_django (Model)streams to work. Components work, but my ModelStream refuses doing what I want. I suppose there are some errors in the documentation, and at least it should be improved here.

  1. First, at templates.rst, you say room.channel.append(... - room in this case (a ModelStream instance) has no "channel" attr. Maybe you mean "stream" here? But there are other things that are missing. "..., or pass a Django instance..." is a bit weird. I think you mean a Model instance that has a stream attached?
  2. RoomListChannel isn't anything that can be referred to in the tutorial before, and is never explained. Is this a stream?
  3. The turbo_subscribe tag section should be before the usage of it.

If you help me a bit to understand I could try to reorganize and corect this page for "newcomers" like me. But I need help - because, like I said, using the docs, I can't get ModelStream to work...

nerdoc commented 2 years ago

Like always, I find the solution to my problems a few minutes after posting the question to stackoverflow or filing a bug, and after hours/days of searching/debugging. But it discovers another missing hint to add to the docs:

  1. {% turbo_subscribe foo_model %} must be placed inside a template block, if you are using them:
    
    {% block content %}
    ...
    {% turbo_subscribe foo_model %}
    ...
    [% endblock %}
scuml commented 2 years ago

The docs do indeed need some extra attention.

(1) - Yes, room.channel is now room.stream (2) - To keep with naming conventions, RoomListChannel should be renamed to RoomListStream. And example of the Stream class itself would be helpful. (4) is related to how django templates work in general. If using an extended template, all template tags and html with the exception of {% load %} must exist inside templates. I'd view this as out of scope for turbo docs, but maybe the problem is with the name of the tag - tubo_subscribe_tag may better signify what is being inserted and remove confusion.

A section dedicated to Turbo + Django development patterns would be immensely helpful as well. I'm keeping track of a few to add.