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

Sample code to replicate issue #397 #407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions example/unicorn/components/issue_397.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Dict

from django_unicorn.components import UnicornView


class Issue397View(UnicornView):
counter: int = 1
counter2: Dict = None

def mount(self):
self.counter2 = {"more": 8}

def inc(self):
self.counter += 1
self.counter2["more"] += 1

def updated_counter(self, value):
print(f"updated_counter: {value}")

def updated_counter2(self, value):
print(f"updated_counter2: {value}")

def updated(self, name, value):
print(f"updated: {name}, {value}")
27 changes: 27 additions & 0 deletions example/unicorn/templates/unicorn/issue-397.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "www/base.html" %}
{% load unicorn %}

{% block content %}

<div unicorn:view>
<div>
counter: {{ counter }}
</div>
<div>
counter2.more: {{ counter2.more }}
</div>

<div>
<button unicorn:click="inc">inc</button>
</div>

<div>
<button unicorn:click="counter=4">counter=4</button>
</div>

<div>
<button unicorn:click="counter2.more=4">counter2.more=4</button>
</div>
</div>

{% endblock content %}
6 changes: 6 additions & 0 deletions example/www/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.urls import path

from example.unicorn.components.direct_view import DirectViewView
from example.unicorn.components.issue_397 import Issue397View

from . import views

Expand All @@ -14,5 +15,10 @@
DirectViewView.as_view(),
name="direct-view",
),
path(
"issue-397",
Issue397View.as_view(),
name="issue-397",
),
path("<str:name>", views.template, name="template"),
]