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

data-bind:list #368

Closed
g105b opened this issue Aug 3, 2022 · 4 comments · Fixed by #415
Closed

data-bind:list #368

g105b opened this issue Aug 3, 2022 · 4 comments · Fixed by #415
Assignees
Milestone

Comments

@g105b
Copy link
Member

g105b commented Aug 3, 2022

To make things nice and simple with nested lists, a new bind key can be used to specify which property of the bound object should be used for automatically binding the nested list.

<ul>
  <li>
    <h1 data-bind:text="name">Name goes here</h1>
    <p>Categories:</p>
    <ul data-bind:list="categories">
      <li data-template data-bind:text="name">Category name goes here</li>
    </ul>
  </li>
</ul>
$iterable = getListOfThings();
$iterable[0]->categories = getCategoriesForThing(); // silly example, but it makes sense
$binder->bindList($iterable);
@g105b g105b self-assigned this Feb 20, 2023
@g105b g105b added this to the v3 milestone Feb 20, 2023
g105b added a commit that referenced this issue Feb 20, 2023
@g105b
Copy link
Member Author

g105b commented Feb 20, 2023

This latest wip commit is nearly there. It's currently detecting data-bind:list just fine, and binding the sub list, all while expanding the nested objects correctly (thanks to #356).

The remaining issue is that the sublist is repeating itself, so item 2 of a sublist contains the same content as item 1.

The unit tests are working nicely by capturing and isolating the yet-to-be-implemented functionality.

Hold that thought - I've been staring at this code all day, and I think it's actually working but my unit tests are not checking the correct indices of the fake data... I think I want to celebrate but I need to get the tests passing first... going for a break now and I will try and complete this before I go out tonight.

g105b added a commit that referenced this issue Feb 20, 2023
@g105b
Copy link
Member Author

g105b commented Feb 20, 2023

It works! The problem was just me being dumb in the unit test... for the last hour or so, the functionality was actually working, but my assumptions in the tests were wrong.

@g105b
Copy link
Member Author

g105b commented Feb 20, 2023

Here's the HTML structure I'm using in the unit tests for this:

<!doctype html>
<h1>Customer overview</h1>

<customer-list>
	<ul>
		<li data-template>
			<customer-details>
				<dl>
					<dt>ID</dt>
					<dd data-bind:text="id">000</dd>
					
					<dt>Name</dt>
					<dd data-bind:text="name">Customer Name!</dd>
					
					<dt>Address</dt>
					<dd>
						<span data-bind:text="address.street">Address Line 1</span>
						<span data-bind:text="address.line2">Address Line 2</span>
						<span data-bind:text="address.cityState">Address City</span>
						<span data-bind:text="address.postcodeZip">Address Postcode</span>
						<span data-bind:text="address.country.name">Address Country</span>
					</dd>
					
					<dt>Latest orders</dt>
					
<!-- the use of a custom element allows data-bind:list to be left blank, so the
list name will be the same as the element name (camel-cased to orderList) -->
					<order-list data-bind:list>
						<ul>
							<li data-template>
								<dl>
									<dt>City / State</dt>
									<dd data-bind:text="shippingAddress.cityState"></dd>
									
									<dt>Subtotal</dt>
									<dd data-bind:text="subtotal">£0.--</dd>
									
									<dt>Shipping</dt>
									<dd data-bind:text="shippingCost">£0.--</dd>
									
									<dt>Total</dt>
									<dd data-bind:text="totalCost">£0.--</dd>
								</dl>
								<h3>Items in order</h3>
								<ul data-bind:list="itemList">
									<li data-template>
										<h4><a href="/item/{{id}}" data-bind:text="title">Item name</a></h4>
										<p data-bind:text="cost">£0.--</p>
									</li>								
								</ul>
							</li>						
						</ul>					
					</order-list>
				</dl>
			</customer-details>		
		</li>
	</ul>
</customer-list>

@g105b
Copy link
Member Author

g105b commented Feb 20, 2023

Before this is made into a PR, I think there's a few tweaks left. The main one is whether or not this functionality works when the root data structure is an object with a list property, rather than in this case a list of multiple objects... basically this works with bindData but does it work with bindList?

g105b added a commit that referenced this issue Feb 27, 2023
… object improvements) (#415)

* build: upgrade dom requirement and loosen version range

* docs: update examples

* feature: trim whitespace when there are only template children
closes #363

* maintenance: phpstorm analysis improvements

* test: refactor test helper class

* wip: add test data for big integration

* test: add failing test to cover nested objects
for #356

* test: add extra cases for nested object test

* feature: allow nesting of object properties
closes #356

* maintenance: static analysis improvement

* test: nested objects with bindgetter functions

* test: isolate issue #367

* test: use `data-template-parent` attribute internally instead of id
closes #367

* test: isolate functionality for #368

* wip: implementation for #368 not yet completed

* feature: data-bind:list
closes #368

* tidy: static analysis improvements

* tidy: types of reflection method improved

* tidy: remove unused import

* tidy: nullable reflection type

* tidy: remove unused elements

* docs: add nested music example
g105b added a commit that referenced this issue Mar 1, 2023
* build: upgrade dom requirement and loosen version range

* docs: update examples

* feature: trim whitespace when there are only template children
closes #363

* maintenance: phpstorm analysis improvements

* test: refactor test helper class

* wip: add test data for big integration

* test: add failing test to cover nested objects
for #356

* test: add extra cases for nested object test

* feature: allow nesting of object properties
closes #356

* maintenance: static analysis improvement

* test: nested objects with bindgetter functions

* test: isolate issue #367

* test: use `data-template-parent` attribute internally instead of id
closes #367

* test: isolate functionality for #368

* wip: implementation for #368 not yet completed

* feature: data-bind:list
closes #368

* tidy: static analysis improvements

* tidy: types of reflection method improved

* tidy: remove unused import

* tidy: nullable reflection type

* tidy: remove unused elements

* docs: add nested music example

* refactor: data-list
for #416

* refactor: data-list
for #416

* refactor: data-list
for #416

* refactor: data-list
for #416
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant