Skip to content

Commit

Permalink
fixed example product_app_c.py (fixes #639)
Browse files Browse the repository at this point in the history
  • Loading branch information
tholzheim committed Dec 5, 2022
1 parent 5196a6d commit bc682d7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
24 changes: 20 additions & 4 deletions docs/blog/vue_comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,31 @@ class Products(jp.Div):
total += product["quantity"]
return total

def react(self, data):
def react(self, data):
self.ul.delete_components()
for product in self.products:
item = jp.Li(a=self.ul)
jp.Input(type='number', product=product, a=item, value=product["quantity"], input='self.product["quantity"] = self.value')
jp.Span(text=f'{product["quantity"]} {product["name"]}', a=item, style='margin-left: 10px')
jp.InputChangeOnly(
type='number',
product=product,
a=item,
value=product["quantity"],
change='self.product["quantity"] = self.value'
)
jp.Span(
text=f'{product["quantity"]} {product["name"]}',
a=item,
style='margin-left: 10px'
)
if product["quantity"] == 0:
jp.Span(text=' - OUT OF STOCK', a=item)
jp.Button(text='Add', a=item, product=product, click='self.product["quantity"] += 1', style='margin-left: 10px')
jp.Button(
text='Add',
a=item,
product=product,
click='self.product["quantity"] += 1',
style='margin-left: 10px'
)
self.total_inventory.text = f'Total Inventory: {self.total_products()}'


Expand Down
22 changes: 19 additions & 3 deletions examples/blog/vue_comparison/product_app_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,27 @@ def react(self, data):
self.ul.delete_components()
for product in self.products:
item = jp.Li(a=self.ul)
jp.Input(type='number', product=product, a=item, value=product["quantity"], input='self.product["quantity"] = self.value')
jp.Span(text=f'{product["quantity"]} {product["name"]}', a=item, style='margin-left: 10px')
jp.InputChangeOnly(
type='number',
product=product,
a=item,
value=product["quantity"],
change='self.product["quantity"] = self.value'
)
jp.Span(
text=f'{product["quantity"]} {product["name"]}',
a=item,
style='margin-left: 10px'
)
if product["quantity"] == 0:
jp.Span(text=' - OUT OF STOCK', a=item)
jp.Button(text='Add', a=item, product=product, click='self.product["quantity"] += 1', style='margin-left: 10px')
jp.Button(
text='Add',
a=item,
product=product,
click='self.product["quantity"] += 1',
style='margin-left: 10px'
)
self.total_inventory.text = f'Total Inventory: {self.total_products()}'


Expand Down

0 comments on commit bc682d7

Please sign in to comment.