Skip to content

Commit

Permalink
Merge pull request #22 from dwyl/remove-refernce-to-metadata-issue#19
Browse files Browse the repository at this point in the history
Remove all references to metadata from README.md to avoid confusion.
  • Loading branch information
miguelmartins17 committed Jan 25, 2020
2 parents 0753320 + 2684589 commit e89bffa
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,28 +271,49 @@ has 3 keys:
+ `done`: a `boolean` indicating if the item is complete or still "todo".


#### What about `metadata` ?
#### What about the `count` of items ?

> The TodoMVC Specification requires us to display a **`counter`**
of the items in the Todo list:
https://github.com/tastejs/todomvc/blob/master/app-spec.md#counter

![javascript-todo-list-count](https://user-images.githubusercontent.com/194400/73112092-e73a5400-3f04-11ea-90f6-d4ae541a129c.png)

In order to display the `count` of items in the Todo list,
we _could_ store 3 values in the model:

+ `total_items` - the total number of items, in this case 3.
+ `completed_items` - the number of completed items. in this case 1.
+ `incomplete_items` - the number of items still to be done; 2.

Each time a `new item` is added to the list
we would need to update
both the `total_items`
and the `incomplete_items`
values in the `model`.
And each time an `item` gets checked off as "done",
we would need to update _both_ the `incomplete_items`
and the `completed_items`.
This is _unnecessary_ effort we can avoid.
We can simply _compute_ these values based on the data in the `todos` Array
and display them for the user without storing any additional data.

Instead of _storing_ any additional data for a `counter` in the model
(_the count of active and completed Todo items_),
we will _compute_ the count and display the count at "runtime".
We don't _need_ to store any additional data in the `model`.
This may use a few CPU cycles computing the `count`
each time the view is rendered but that's "OK"!
Even on an _ancient_ Android device
this will only take a millisecond to compute and
won't "slow down" the app or affect UX.

> Metadata is a set of data that describes
and gives information about other data.
https://en.wikipedia.org/wiki/Metadata
See below for how the three counts are computed.

There are two types of `metadata` in a Todo List App:
+ `id` - each todo item has an `id`, this is the item's position in the list.
+ `count` - the count of items according to their state of _completion_.
e.g: in the model above there are 3 todo items in the `todos` Array;
2 items which are "active" (`done=false`)
and 1 which is "done" (`done=true`).

Rather than _storing_ "metadata" in the model
(_e.g: the count of active and completed Todo items_)
we will "compute" (derive) it "at runtime" to keep the `model` simple.
This may "waste" a few CPU cycles computing the count but that's "OK"!
Even on an _ancient_ Android device
this will only take a millisecond to compute and
won't "slow down" the app or affect UX.


#### `model` _Test_

Given that the `model` is "just data"
Expand Down

0 comments on commit e89bffa

Please sign in to comment.