-
Notifications
You must be signed in to change notification settings - Fork 1
Don't collapse one line of code #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Instead of connecting to a real backend API or web service, we’ll use [can-fixture fixtures] | ||
to “mock” an API. Whenever an [AJAX](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) | ||
request is made, the fixture will “capture” the request and instead respond with mock data. | ||
|
||
> **Note:** if you open your browser’s Network panel, you will *not* see any network requests. | ||
> You can see the fixture requests and responses in your browser’s Console panel. | ||
|
||
How fixtures work is outside the scope of this tutorial and not necessary to understand to continue, | ||
but you can learn more in the [can-fixture] documentation. | ||
|
||
## Defining a custom element with CanJS | ||
|
||
We mentioned above that CanJS helps you define custom elements. We call these [can-component components]. | ||
|
||
Add the following to the **JS** tab in your CodePen: | ||
|
||
```js | ||
// Creates a mock backend with 3 todos | ||
import { todoFixture } from "//unpkg.com/can-demo-models@5"; | ||
todoFixture(3); | ||
|
||
import { Component } from "//unpkg.com/can@5/core.mjs"; | ||
|
||
Component.extend({ | ||
tag: "todos-app", | ||
view: ` | ||
<h1>Today’s to-dos</h1> | ||
`, | ||
ViewModel: { | ||
} | ||
}); | ||
``` | ||
<span line-highlight='2-7,9-14,only'/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cherifGsoul can you explain this logic change? Would this show the lines between a set of highlights like:
range[0] > current + padding
would be true whenrange[0]
is33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justinbmeyer The logic is to compare the first line and the last line of collapsible:
current
which is initialized to1
or calculated in this expression at the end of the loopcurrent = (range[1] || range[0]) + padding + 1
collapseEnd
is calculated based on the first itemrange[0]
of the new range of line highlightcollapseEnd = (range[0] - 1 - padding)
In short:
current = currentRange[1] + 1 + padding
next = nextRange[0] - 1 - padding
next - current
should be greater than1
to make a collapsibleSo for
@highlight 1-3,33-55
we have a collapsible between[7, 29]
and it shows only the 3 lines for padding between highlights:current = 3 + 1 + 3 // => start collapsible from line 7
next = 33 - 1 - 3 // => close collapsing at the line 29