Skip to content

Commit

Permalink
Sample code to replicate issue #397.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamghill committed May 14, 2022
1 parent 0a4e285 commit fc19fe1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
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"),
]

0 comments on commit fc19fe1

Please sign in to comment.