-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00093ae
commit 5c86419
Showing
17 changed files
with
122 additions
and
123 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
This file contains 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 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,9 @@ | ||
# Guide - Debugging with the inspector | ||
|
||
A good tool will always help you for good work. In the web development, the inspector is the right choice. It is included in most browsers and accessible by a right-click. | ||
|
||
The two most useful tabs are *Console* and *Network*. The first one allows you to communicate with the Javascript engine of the current page, for example to manipulate a model or view its data. The second one allows you to check all files loaded with their status and all calls to the server (ajax and websocket). | ||
|
||
When things get wrong, the script stops and the error is shown in the *Console*. Click on it to show the source code with the associated error. You can also force the third tab *Source code* to be shown at some point by inserting the statement `debugger;` inside your Javascript code. You wil then be able to see the stack and values. | ||
|
||
Finally, a fourth tab *Element* or *DOM* shown the DOM tree of the current page. You can see with it if the view is renderer as expected but also modify it on the fly to see what happens before coding it in your code. For example you can see if a layout is well by changing a class element or directly the CSS values of the page. |
This file contains 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 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 |
---|---|---|
@@ -1 +1,23 @@ | ||
# Guide | ||
# Guide - Write DOM with Javascript without HTML | ||
|
||
The foundamental part of a browser is the view, it is defined by the *DOM* and *HTML* is the langage to express it. | ||
|
||
The DOM can be manipulated with Javascript like this: | ||
|
||
```js | ||
const div = document.createElement('div'); | ||
div.textContent = 'Hello'; | ||
document.body.append(div); | ||
``` | ||
|
||
This way, you can build everything you want for the user to interact with it, it uses the imperative programming paradigm. But in a large application this can leads to inconsistencies because a human is in charge of synchronizing the data model with the view by removing, updating and inserting DOM elements. This was done like this for years within the area of jQuery. | ||
|
||
More recently in the area of AngularJS and ReactJS, a new paradigm has been used, the declarative programming. The principal is to *declare* the view depending on the data model, just like a function. For one input, we always have one view output. The magic is done by a diff algorithm which will take care of the updates of the DOM according to the new "view output" generated by your declared view. Let's take a simple example: | ||
|
||
```js | ||
h('div', model.name) | ||
``` | ||
|
||
This declare the equivalent of `<div>Hello</div>` with `model.name = 'Hello'`. When we modify the name attribute, the `h` function will produce a new view because the argument has changed. In the background the div element will *not be recreated but updated*. | ||
|
||
This way of declaring the DOM is called Hyperscript, more information in [this guide](./vnodes.md). |
This file contains 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 |
---|---|---|
@@ -1 +1,64 @@ | ||
# Guide | ||
# Guide - How to scale and architecture | ||
|
||
### Files | ||
|
||
In the tutorials you can see a single model and a single view. But a large application cannot be made as a large file. A good way is to split the code into module like this: | ||
|
||
``` | ||
- user (folder, camelCase) | ||
- User.js (model, PascalCase) | ||
- userList.js (view, camelCase) | ||
- userItem.js (view, camelCase) | ||
- userAvatar.js (view, camelCase) | ||
- user.css (facultative style, camelCase) | ||
``` | ||
|
||
This allows you to have everything concerning a module in the same place. You can have as many modules as you want. At some point you can ever create a super-module as a folder for some parts of your application. | ||
|
||
For common things like a `header.js` or `alert.js`, a `common` folder can be made. | ||
|
||
### View | ||
|
||
Inside the view files, avoid to have a big function containing all your page. Try to split in smaller functions and pass the model as parameter each time. | ||
|
||
```js | ||
export function userList(model) { | ||
return h('ul', model.user.list.map(user => userListRow(model, user))); | ||
} | ||
|
||
function userListRow(model, user) { | ||
return h('li', user.name); | ||
} | ||
``` | ||
|
||
### Model | ||
|
||
The `Observable` model can be, like the view, a tree and all notification event can be bubbled to the root model like this: | ||
|
||
```js | ||
class Model extends Observable { | ||
constructor() { | ||
super(); | ||
this.submodel = new SubModel(); | ||
this.submodel.bubbleTo(this); | ||
} | ||
} | ||
|
||
class SubModel extends Observable { | ||
constructor() { | ||
super(); | ||
this.count = 0; | ||
} | ||
|
||
increment() { | ||
this.count++; | ||
this.notify(); | ||
} | ||
} | ||
|
||
const model = new Model(); | ||
``` | ||
|
||
When a call to `model.submodel.increment()` is made, `model` will be notified and will call all callbacks registered via `model.observe(callbackFunction)`. | ||
|
||
[Global view of the architecture](../architecture.jpeg) |
File renamed without changes.
This file contains 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 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 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.