Skip to content

Commit

Permalink
fix: Correct stale data in nested frames
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbukachi committed Mar 8, 2021
1 parent 4c412f7 commit 1d2a018
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
5 changes: 5 additions & 0 deletions example/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def messages_list():
messages = Message.query.all()
return render_template('messages.html', messages=messages)

@app.route('/messages_count')
def messages_count():
count = Message.query.count()
return render_template('messages_count.html', count=count)

@app.route('/add_message', methods=('GET', 'POST'))
def add_message():
message = request.form['message']
Expand Down
14 changes: 9 additions & 5 deletions example/templates/messages.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<ul>
{% for message in messages %}
<li>{{ message.content }}</li>
{% endfor %}
</ul>
{% from "wire/macros.html" import wire_frame, wire_trigger, wire_mutation %}
<div>
<ul>
{% for message in messages %}
<li>{{ message.content }}</li>
{% endfor %}
</ul>
{{ wire_frame(id='messages_count', initial=url_for('messages_count')) }}
</div>
3 changes: 3 additions & 0 deletions example/templates/messages_count.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Total messages count: <b>{{ count }}</b>
</div>
2 changes: 1 addition & 1 deletion flask_wire/static/js/bundle.js

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class WireFrame {

init(element) {
if (element.children.length) {
this.body = DomUtils.selectFirstElementWithAttribute(element, 'wire:body')
this.errorBody = DomUtils.selectFirstElementWithAttribute(element, 'wire:error-body')
this.loader = DomUtils.selectFirstElementWithAttribute(element, 'wire:loader.*')
}
Expand All @@ -43,13 +42,10 @@ class WireFrame {
}

updateBody(body) {
if (this.body) {
this.body.innerHTML = body

// Fire events signaling completion of data fetch
dispatch('wire:frame_load')
dispatch(`wire:frame_load ${this.id}`)
}
document.querySelector(`div[wire\\:frame='${this.id}'] > div[wire\\:body='']`).innerHTML = body
// Fire events signaling completion of data fetch
dispatch('wire:frame_load')
dispatch(`wire:frame_load ${this.id}`)
}

updateSource(source, onSourceDataFetched = null) {
Expand All @@ -62,7 +58,7 @@ class WireFrame {
return template.content.firstChild
}

fetchDataFromSource(source, target, onDone = null) {
fetchDataFromSource(source, onDone = null) {
this.hideError()
this.showLoader()

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import codecs

version = '1.0.1'
version = '1.0.2'

setup(
name='Flask-Wire',
Expand Down

0 comments on commit 1d2a018

Please sign in to comment.