simplyview 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/simply.everything.js +22 -5
- package/js/simply.viewmodel.js +20 -5
- package/package.json +7 -2
- package/docs/examples.md +0 -82
- package/docs/readme.md +0 -33
- package/docs/simply.action.md +0 -42
- package/docs/simply.activate.md +0 -27
- package/docs/simply.api.md +0 -188
- package/docs/simply.app.md +0 -27
- package/docs/simply.collect.md +0 -64
- package/docs/simply.command.md +0 -110
- package/docs/simply.include.md +0 -61
- package/docs/simply.keyboard.md +0 -60
- package/docs/simply.path.md +0 -3
- package/docs/simply.route.md +0 -133
- package/docs/simply.view.md +0 -53
- package/docs/simply.viewmodel.md +0 -3
- package/examples/commands.html +0 -70
- package/examples/counter.html +0 -52
- package/examples/examples.css +0 -3
- package/examples/github.html +0 -39
- package/examples/include/fifth.js +0 -1
- package/examples/include/first.js +0 -1
- package/examples/include/include.html +0 -4
- package/examples/include/include2.html +0 -1
- package/examples/include/index.html +0 -18
- package/examples/include/scripts.html +0 -16
- package/examples/include/third.js +0 -3
- package/examples/todo.html +0 -48
- package/examples/viewmodel.html +0 -359
- package/make +0 -18
- package/test/simply.route.test.js +0 -102
|
@@ -1601,6 +1601,7 @@ properties for a given parent, keep seperate index for this?
|
|
|
1601
1601
|
load();
|
|
1602
1602
|
} else {
|
|
1603
1603
|
global.document.addEventListener('simply-content-loaded', function() {
|
|
1604
|
+
console.log('switching...')
|
|
1604
1605
|
load();
|
|
1605
1606
|
});
|
|
1606
1607
|
}
|
|
@@ -1619,10 +1620,18 @@ properties for a given parent, keep seperate index for this?
|
|
|
1619
1620
|
})(this);
|
|
1620
1621
|
(function(global) {
|
|
1621
1622
|
'use strict';
|
|
1623
|
+
|
|
1624
|
+
function etag() {
|
|
1625
|
+
let d = '';
|
|
1626
|
+
while (d.length < 32) d += Math.random().toString(16).substr(2);
|
|
1627
|
+
const vr = ((parseInt(d.substr(16, 1), 16) & 0x3) | 0x8).toString(16);
|
|
1628
|
+
return `${d.substr(0, 8)}-${d.substr(8, 4)}-4${d.substr(13, 3)}-${vr}${d.substr(17, 3)}-${d.substr(20, 12)}`;
|
|
1629
|
+
}
|
|
1622
1630
|
|
|
1623
1631
|
function ViewModel(name, data, options) {
|
|
1624
1632
|
this.name = name;
|
|
1625
1633
|
this.data = data || [];
|
|
1634
|
+
this.data.etag = etag();
|
|
1626
1635
|
this.view = {
|
|
1627
1636
|
options: {},
|
|
1628
1637
|
data: [] //Array.from(this.data).slice()
|
|
@@ -1645,15 +1654,22 @@ properties for a given parent, keep seperate index for this?
|
|
|
1645
1654
|
// this.data is a reference to the data passed, so that any changes in it will get applied
|
|
1646
1655
|
// to the original
|
|
1647
1656
|
this.data = params.data;
|
|
1657
|
+
this.data.etag = etag()
|
|
1648
1658
|
}
|
|
1649
1659
|
// the view is a shallow copy of the array, so that changes in sort order and filtering
|
|
1650
1660
|
// won't get applied to the original, but databindings on its children will still work
|
|
1651
1661
|
this.view.data = Array.from(this.data).slice();
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
plugins.
|
|
1655
|
-
|
|
1662
|
+
this.view.data.etag = this.data.etag;
|
|
1663
|
+
let data = this.view.data;
|
|
1664
|
+
let plugins = this.plugins.start.concat(this.plugins.select, this.plugins.order, this.plugins.render, this.plugins.finish);
|
|
1665
|
+
plugins.forEach(plugin => {
|
|
1666
|
+
data = plugin.call(this, params, data);
|
|
1667
|
+
if (!data) {
|
|
1668
|
+
data = this.view.data;
|
|
1669
|
+
}
|
|
1670
|
+
this.view.data = data
|
|
1656
1671
|
});
|
|
1672
|
+
this.view.data = data;
|
|
1657
1673
|
|
|
1658
1674
|
if (global.editor) {
|
|
1659
1675
|
global.editor.addDataSource(this.name,{
|
|
@@ -1778,7 +1794,8 @@ properties for a given parent, keep seperate index for this?
|
|
|
1778
1794
|
createFilter: createFilter,
|
|
1779
1795
|
createSort: createSort,
|
|
1780
1796
|
createPaging: createPaging,
|
|
1781
|
-
updateDataSource: updateDataSource
|
|
1797
|
+
updateDataSource: updateDataSource,
|
|
1798
|
+
etag
|
|
1782
1799
|
};
|
|
1783
1800
|
|
|
1784
1801
|
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
package/js/simply.viewmodel.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
(function(global) {
|
|
2
2
|
'use strict';
|
|
3
|
+
|
|
4
|
+
function etag() {
|
|
5
|
+
let d = '';
|
|
6
|
+
while (d.length < 32) d += Math.random().toString(16).substr(2);
|
|
7
|
+
const vr = ((parseInt(d.substr(16, 1), 16) & 0x3) | 0x8).toString(16);
|
|
8
|
+
return `${d.substr(0, 8)}-${d.substr(8, 4)}-4${d.substr(13, 3)}-${vr}${d.substr(17, 3)}-${d.substr(20, 12)}`;
|
|
9
|
+
}
|
|
3
10
|
|
|
4
11
|
function ViewModel(name, data, options) {
|
|
5
12
|
this.name = name;
|
|
6
13
|
this.data = data || [];
|
|
14
|
+
this.data.etag = etag();
|
|
7
15
|
this.view = {
|
|
8
16
|
options: {},
|
|
9
17
|
data: [] //Array.from(this.data).slice()
|
|
@@ -26,14 +34,20 @@
|
|
|
26
34
|
// this.data is a reference to the data passed, so that any changes in it will get applied
|
|
27
35
|
// to the original
|
|
28
36
|
this.data = params.data;
|
|
37
|
+
this.data.etag = etag()
|
|
29
38
|
}
|
|
30
39
|
// the view is a shallow copy of the array, so that changes in sort order and filtering
|
|
31
40
|
// won't get applied to the original, but databindings on its children will still work
|
|
32
41
|
this.view.data = Array.from(this.data).slice();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
plugins.
|
|
36
|
-
|
|
42
|
+
this.view.data.etag = this.data.etag;
|
|
43
|
+
let data = this.view.data;
|
|
44
|
+
let plugins = this.plugins.start.concat(this.plugins.select, this.plugins.order, this.plugins.render, this.plugins.finish);
|
|
45
|
+
plugins.forEach(plugin => {
|
|
46
|
+
data = plugin.call(this, params, data);
|
|
47
|
+
if (!data) {
|
|
48
|
+
data = this.view.data;
|
|
49
|
+
}
|
|
50
|
+
this.view.data = data
|
|
37
51
|
});
|
|
38
52
|
|
|
39
53
|
if (global.editor) {
|
|
@@ -159,7 +173,8 @@
|
|
|
159
173
|
createFilter: createFilter,
|
|
160
174
|
createSort: createSort,
|
|
161
175
|
createPaging: createPaging,
|
|
162
|
-
updateDataSource: updateDataSource
|
|
176
|
+
updateDataSource: updateDataSource,
|
|
177
|
+
etag
|
|
163
178
|
};
|
|
164
179
|
|
|
165
180
|
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplyview",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Library to rapidly build UI components, using declarative tools",
|
|
5
5
|
"main": "dist/simply.everything.js",
|
|
6
6
|
"directories": {
|
|
@@ -27,5 +27,10 @@
|
|
|
27
27
|
"homepage": "https://github.com/simplyedit/simplyview#readme",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"jest": "^24.9.0"
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"README.md",
|
|
33
|
+
"dist/",
|
|
34
|
+
"js/"
|
|
35
|
+
]
|
|
31
36
|
}
|
package/docs/examples.md
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# Examples
|
|
2
|
-
|
|
3
|
-
## Counter
|
|
4
|
-
|
|
5
|
-
The counter app is an example to introduce the basic concepts. Here is the HTML:
|
|
6
|
-
|
|
7
|
-
```html
|
|
8
|
-
<div id="counterApp">
|
|
9
|
-
<input type="text" data-simply-field="counter">
|
|
10
|
-
<button data-simply-command="add1">+</button>
|
|
11
|
-
<button data-simply-command="sub1">-</button>
|
|
12
|
-
<div>Counter is now: <span data-simply-field="counter"></span></div>
|
|
13
|
-
</div>
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
It uses two components of SimplyView and SimplyEdit, through
|
|
17
|
-
`data-simply-command` and `data-simply-field`.
|
|
18
|
-
|
|
19
|
-
`data-simply-command` is handled by [simply.command](simply.command.md). Both
|
|
20
|
-
commands are defined on buttons, so they will trigger when the button is
|
|
21
|
-
pressed. The javascript code tied to these commands is defined with the
|
|
22
|
-
[simply.app](simply.app.md) component:
|
|
23
|
-
|
|
24
|
-
```javascript
|
|
25
|
-
var counterApp = simply.app({
|
|
26
|
-
container: document.getElementById('counterApp'),
|
|
27
|
-
commands: {
|
|
28
|
-
add1: function() {
|
|
29
|
-
counterApp.view.counter++;
|
|
30
|
-
},
|
|
31
|
-
sub1: function() {
|
|
32
|
-
counterApp.view.counter--;
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
view: {
|
|
36
|
-
counter: 1
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
simply.app is a wrapper that combines a number of components with a single
|
|
42
|
-
configuration parameter. The commands section here is passed on to simply.command.
|
|
43
|
-
|
|
44
|
-
When you press the button with `data-simply-command="add1"`, the command
|
|
45
|
-
handler for this app is triggered and searches its commands for 'add1'.
|
|
46
|
-
It then calls this javascript function and it will increase
|
|
47
|
-
`counterApp.view.counter`.
|
|
48
|
-
|
|
49
|
-
This is where the second component, which uses `data-simply-field`, comes in.
|
|
50
|
-
The `counterApp.view` object is automatically tied to SimplyEdit, by simply.app.
|
|
51
|
-
So whenever you update a variable inside `counterApp.view`, SimplyEdit will
|
|
52
|
-
also update any HTML element which references the same variable.
|
|
53
|
-
|
|
54
|
-
In this case `counterApp.view.counter` is tied to the input element with
|
|
55
|
-
`data-simply-field="counter"`.
|
|
56
|
-
|
|
57
|
-
SimplyEdit also does the reverse, whenever you change the input value,
|
|
58
|
-
SimplyEdit will also change the `counterApp.view.counter` value. This is called
|
|
59
|
-
two-way databinding.
|
|
60
|
-
|
|
61
|
-
Two-way databinding is not instantanous, so whenever you change a value in
|
|
62
|
-
javascript or in the DOM, it will take a short while for SimplyEdit to update
|
|
63
|
-
the other side as well. There are a number of events that will tell you when
|
|
64
|
-
the values are in sync again.
|
|
65
|
-
|
|
66
|
-
## Todo
|
|
67
|
-
|
|
68
|
-
The TodoMVC application is a standard web application implemented in many different
|
|
69
|
-
javascript frameworks. We've build one using SimplyEdit and SimplyView, which you
|
|
70
|
-
can find at [todomvc.simplyedit.io](https://todomvc.simplyedit.io/).
|
|
71
|
-
|
|
72
|
-
The code is on github at
|
|
73
|
-
[github.com/simplyedit/todomvc](https://github.com/simplyedit/todomvc). The
|
|
74
|
-
Readme explains how it is build.
|
|
75
|
-
|
|
76
|
-
## Hackernews PWA
|
|
77
|
-
|
|
78
|
-
Just like the TodoMVC application, the Hackernews PWA is also a standard web
|
|
79
|
-
application implemented in many frameworks. You can find the SimplyEdit/SimplyView
|
|
80
|
-
version at [hnpwa.simplyedit.io](https://hnpwa.simplyedit.io/). The code is at
|
|
81
|
-
[github.com/simplyedit/hnpwa](https://github.com/simplyedit/hnpwa) and the
|
|
82
|
-
Readme explains how it was built.
|
package/docs/readme.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Introduction
|
|
2
|
-
|
|
3
|
-
SimplyView is a set of seperate components that allow you to rapidly build web
|
|
4
|
-
application user interfaces. They are designed to work with modern reactive
|
|
5
|
-
libraries, like that included in [SimplyEdit](https://simplyedit.io/).
|
|
6
|
-
|
|
7
|
-
SimplyView seperates structure - HTML - from behaviour - javascript. There is
|
|
8
|
-
never a need to write HTML inside your javascript code. There is also never a
|
|
9
|
-
need to write javascript - or any other kind of code - inside your HTML.
|
|
10
|
-
This strict seperation allows for a much easier workflow between designers and developers.
|
|
11
|
-
|
|
12
|
-
This seperation also makes it possible, even easy, to re-use and upgrade
|
|
13
|
-
existing web applications. There is no need to rewrite everthing from scratch.
|
|
14
|
-
SimplyView works well with jQuery. In rare cases you can use the simply.activate
|
|
15
|
-
component to make sure your legacy javascript can react to changes in the HTML
|
|
16
|
-
structure.
|
|
17
|
-
|
|
18
|
-
SimplyView is not a framework, but a selection of components. There is a
|
|
19
|
-
simply.app component which ties them all together, but you don't need it to
|
|
20
|
-
use any of them.
|
|
21
|
-
|
|
22
|
-
- [simply.app](simply.app.md)
|
|
23
|
-
- [simply.route](simply.route.md)
|
|
24
|
-
- [simply.command](simply.command.md)
|
|
25
|
-
- [simply.action](simply.action.md)
|
|
26
|
-
- [simply.collect](simply.collect.md)
|
|
27
|
-
- [simply.activate](simply.activate.md)
|
|
28
|
-
- [simply.include](simply.include.md)
|
|
29
|
-
- [simply.api](simply.api.md)
|
|
30
|
-
- [simply.viewmodel](simply.viewmodel.md)
|
|
31
|
-
- [simply.path](simply.path.md)
|
|
32
|
-
|
|
33
|
-
Here are [some examples](examples.md) that use parts of SimplyView.
|
package/docs/simply.action.md
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# simply.action
|
|
2
|
-
|
|
3
|
-
Actions are a standardized way to define a kind of API for your user
|
|
4
|
-
interface. They are meant to be used together with routes and commands.
|
|
5
|
-
|
|
6
|
-
In this case the routes and commands are tightly bound to your URL
|
|
7
|
-
structure and your HTML structure respectively.
|
|
8
|
-
|
|
9
|
-
Actions should be decoupled from those. An action should just be a method
|
|
10
|
-
that updates the application state. The parameters for an action should
|
|
11
|
-
be the logical parameters for that update.
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
var myApp = simply.app({
|
|
15
|
-
commands: {
|
|
16
|
-
addTodo: function(form, values) {
|
|
17
|
-
form.elements.todo.value = '';
|
|
18
|
-
this.app.actions.addTodo(values.todo);
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
actions: {
|
|
23
|
-
addTodo: function(todo) {
|
|
24
|
-
this.app.view.todos.push(todo);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
By structuring your application in this way, it is easy to add different
|
|
31
|
-
user interface modes which accomplish the same action. So you can create a
|
|
32
|
-
route as well as a command, that both trigger the same action. Or later you
|
|
33
|
-
can add keyboard shortcuts or gestures, without having to copy the logic of
|
|
34
|
-
your action.
|
|
35
|
-
|
|
36
|
-
You can add actions later by just defining them in the actions object:
|
|
37
|
-
|
|
38
|
-
```javascript
|
|
39
|
-
myApp.actions.anotherAction = function(...arguments) {
|
|
40
|
-
...
|
|
41
|
-
};
|
|
42
|
-
```
|
package/docs/simply.activate.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# simply.activate
|
|
2
|
-
|
|
3
|
-
simply.activate is a component to automatically initialize HTML elements with
|
|
4
|
-
javascript as they appear in the DOM.
|
|
5
|
-
|
|
6
|
-
```javascript
|
|
7
|
-
simply.activate.addListener('autosize',function() {
|
|
8
|
-
$.autosize(this);
|
|
9
|
-
});
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
```html
|
|
13
|
-
<textarea data-simply-activate="autosize"></textarea>
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
The `addListener` method takes two arguments, a name and a callback method.
|
|
17
|
-
The name is what you use in the html `data-simply-activate` attribute. The
|
|
18
|
-
callback method is then called whenever the DOM element with that attribute
|
|
19
|
-
is added to the dom. It is also called on load.
|
|
20
|
-
|
|
21
|
-
The callback method has no arguments, instead it is called on the DOM element
|
|
22
|
-
itself. `this` references the DOM element.
|
|
23
|
-
|
|
24
|
-
Now you can use any 'legacy' component, in this case a jQuery textarea
|
|
25
|
-
resizer, that needs to initialize HTML elements. Simply.activate will
|
|
26
|
-
trigger the initialization routine whenever the element is inserted into the
|
|
27
|
-
dom, no matter how or when this happens.
|
package/docs/simply.api.md
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
# simply.api
|
|
2
|
-
|
|
3
|
-
Simply.api is a library that makes it easier to connect to online API's,
|
|
4
|
-
like REST or JSON-RPC api's. It contains a simplified fetch() method as well
|
|
5
|
-
as a proxy that allows you to call remote API's as if they were a local
|
|
6
|
-
library. E.g.:
|
|
7
|
-
|
|
8
|
-
```javascript
|
|
9
|
-
const githubApi = simply.api.proxy({
|
|
10
|
-
baseURL: 'https://api.github.com',
|
|
11
|
-
headers: {
|
|
12
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
13
|
-
'User-Agent': 'SimplyApi'
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
githubApi.users.poef()
|
|
18
|
-
.then(user => {
|
|
19
|
-
console.log(user);
|
|
20
|
-
});
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
The proxy() method returns an object that will create new proxy objects on
|
|
24
|
-
the fly for any property you access on it, like the 'users' property above.
|
|
25
|
-
When you call such a property as a function, the proxy object will convert
|
|
26
|
-
the property path to a URL and fetch it.
|
|
27
|
-
|
|
28
|
-
In this case the githubApi.users.poef() call is converted to a GET request
|
|
29
|
-
with the url: 'https://api.github.com/users/poef'.
|
|
30
|
-
|
|
31
|
-
You can also pass arguments to the method, by passing an object with key
|
|
32
|
-
value pairs:
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
githubApi.users.octocat.hovercard({
|
|
36
|
-
subject_type: 'repository',
|
|
37
|
-
subject_id: 1300192
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Which is converted in a fetch() request like this:
|
|
42
|
-
|
|
43
|
-
```javascript
|
|
44
|
-
GET https://api.github.com/users/octocat/hovercard?subject_type=repository&subject_id=1300192
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
If you want to use a different HTTP Verb, like 'POST', add that as the last entry like
|
|
48
|
-
this:
|
|
49
|
-
|
|
50
|
-
```javascript
|
|
51
|
-
githubApi.user.keys.post({
|
|
52
|
-
key: "mykey"
|
|
53
|
-
})
|
|
54
|
-
.then(result => {
|
|
55
|
-
console.log(result);
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
The default verb methods that simply.api understands are GET and POST. If
|
|
60
|
-
you need more, declare them in the options object under the 'verbs' key.
|
|
61
|
-
|
|
62
|
-
You can add any option recognized by the default fetch() api in the proxy
|
|
63
|
-
options object, see [the init property
|
|
64
|
-
here](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#parameters).
|
|
65
|
-
In addition the proxy recognizes these options:
|
|
66
|
-
|
|
67
|
-
- responseFormat
|
|
68
|
-
- paramsFormat
|
|
69
|
-
- verbs
|
|
70
|
-
- user and password
|
|
71
|
-
- handlers
|
|
72
|
-
|
|
73
|
-
## responseFormat
|
|
74
|
-
|
|
75
|
-
This declares the expected result format of the remote API. The valid
|
|
76
|
-
options are:
|
|
77
|
-
|
|
78
|
-
- text
|
|
79
|
-
- formData
|
|
80
|
-
- blob
|
|
81
|
-
- arrayBuffer
|
|
82
|
-
- unbuffered
|
|
83
|
-
- json
|
|
84
|
-
|
|
85
|
-
The default is 'json'. Unlike the standard fetch() api, simply.api.fetch
|
|
86
|
-
(used by the proxy object) automatically parses and returns the result, as a
|
|
87
|
-
Promise. If an error is returned - the response.ok flag is false - then it
|
|
88
|
-
will throw an error object with the status, message and full response
|
|
89
|
-
object.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
## paramsFormat
|
|
93
|
-
|
|
94
|
-
Available formats are:
|
|
95
|
-
- search
|
|
96
|
-
- formData
|
|
97
|
-
- json
|
|
98
|
-
|
|
99
|
-
When the fetch method is GET, the format is forced to 'search'.
|
|
100
|
-
|
|
101
|
-
### search
|
|
102
|
-
This option sets the parameter format for the remote API. When set to search,
|
|
103
|
-
the parameters are send as a url encoded parameters in the URL of the
|
|
104
|
-
request.
|
|
105
|
-
|
|
106
|
-
### formData
|
|
107
|
-
Sets the parameter format to the default formdata encoding, add the
|
|
108
|
-
parameters to the body of the request.
|
|
109
|
-
|
|
110
|
-
### json
|
|
111
|
-
Encodes the parameters as a json string and adds it to the body of the
|
|
112
|
-
request.
|
|
113
|
-
|
|
114
|
-
## verbs
|
|
115
|
-
|
|
116
|
-
By default simply.api.proxy understands the GET and POST verbs. You can add
|
|
117
|
-
more by setting this option, e.g:
|
|
118
|
-
|
|
119
|
-
```javascript
|
|
120
|
-
const githubApi = simply.api.proxy({
|
|
121
|
-
baseURL: 'https://api.github.com',
|
|
122
|
-
headers: {
|
|
123
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
124
|
-
'User-Agent': 'SimplyApi'
|
|
125
|
-
},
|
|
126
|
-
verbs: [ 'get', 'post', 'put', 'delete' ]
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Now you can call the put() and delete() methods on the proxy as well:
|
|
131
|
-
|
|
132
|
-
```javascript
|
|
133
|
-
githubApi.user.following.octocat.delete();
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Note: the verb names are automatically uppercased when sent.
|
|
137
|
-
|
|
138
|
-
## user and password
|
|
139
|
-
|
|
140
|
-
If you set a user and password property in the options to simply.api.proxy,
|
|
141
|
-
these will be converted to a basic authentication header and added to each
|
|
142
|
-
request.
|
|
143
|
-
|
|
144
|
-
## handlers
|
|
145
|
-
|
|
146
|
-
Some API's require extra handling for requests or parsing of responses. You
|
|
147
|
-
can override or extend the default handlers here. The available handlers are:
|
|
148
|
-
|
|
149
|
-
- fetch
|
|
150
|
-
- result
|
|
151
|
-
- error
|
|
152
|
-
|
|
153
|
-
A minimal definition for these handlers that maintains the default behaviour
|
|
154
|
-
is:
|
|
155
|
-
|
|
156
|
-
```javascript
|
|
157
|
-
const githubApi = simply.api.proxy({
|
|
158
|
-
baseURL: 'https://api.github.com',
|
|
159
|
-
headers: {
|
|
160
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
161
|
-
'User-Agent': 'SimplyApi'
|
|
162
|
-
},
|
|
163
|
-
verbs: [ 'get', 'post', 'put', 'delete' ],
|
|
164
|
-
handlers: {
|
|
165
|
-
fetch: function(verb, params, options) {
|
|
166
|
-
// prepare stuff here
|
|
167
|
-
return simply.api.fetch(verb, params, options)
|
|
168
|
-
.then(response => {
|
|
169
|
-
// do some more stuff here
|
|
170
|
-
return response;
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
result: function(result, options) {
|
|
174
|
-
// ditto
|
|
175
|
-
return simply.api.getResult(result, options)
|
|
176
|
-
.then(result => {
|
|
177
|
-
// more doing
|
|
178
|
-
return result;
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
error: function(error, options) {
|
|
182
|
-
// ...
|
|
183
|
-
simply.api.logError(error, options); // no return value here
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
```
|
|
188
|
-
|
package/docs/simply.app.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# simply.app
|
|
2
|
-
|
|
3
|
-
simply.app provides a simple starting point to build web applications:
|
|
4
|
-
|
|
5
|
-
```javascript
|
|
6
|
-
var myApp = simply.app({
|
|
7
|
-
routes: {
|
|
8
|
-
'/:section/': function(params) { ... }
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
commands: { ... },
|
|
12
|
-
|
|
13
|
-
actions: { ... },
|
|
14
|
-
|
|
15
|
-
container: document.getElementById('myApp'),
|
|
16
|
-
|
|
17
|
-
view: {
|
|
18
|
-
myVariable: 'foo'
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
It combines [simply.route](simply.route.md),
|
|
26
|
-
[simply.command](simply.command.md), [simply.action](simply.action.md) and
|
|
27
|
-
[simply.view](simply.view.md) into a single application wrapper.
|
package/docs/simply.collect.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# simply.collect
|
|
2
|
-
|
|
3
|
-
simply.collect allows you to create auto updating forms, just by adding a few
|
|
4
|
-
attributes to the form and its elements:
|
|
5
|
-
|
|
6
|
-
```javascript
|
|
7
|
-
function getAddress(elements) {
|
|
8
|
-
if (elements.zipcode.value && elements.housenr.value) {
|
|
9
|
-
zipcodeAPI
|
|
10
|
-
.getAddress(elements.zipcode.value,elements.country.value)
|
|
11
|
-
.then(function(address) {
|
|
12
|
-
elements.street.value = address.street;
|
|
13
|
-
elements.city.value = address.city;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
simply.collect.addListener('address', getAddress);
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
```html
|
|
22
|
-
<form>
|
|
23
|
-
<div data-simply-collect="address">
|
|
24
|
-
<label>
|
|
25
|
-
Zipcode: <input name="zipcode" data-simply-element="zipcode">
|
|
26
|
-
</label>
|
|
27
|
-
<label>
|
|
28
|
-
House NR: <input name="housenumber" data-simply-element="housenr">
|
|
29
|
-
</label>
|
|
30
|
-
<label>
|
|
31
|
-
Street: <input name="street" data-simply-element="street">
|
|
32
|
-
</label>
|
|
33
|
-
<label>
|
|
34
|
-
City: <input name="city" data-simply-element="city">
|
|
35
|
-
</label>
|
|
36
|
-
</div>
|
|
37
|
-
</form>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
The listener will get called whenever any of the elements changes. You can add
|
|
41
|
-
as many forms and as many container elements with data-simply-collect as you want.
|
|
42
|
-
|
|
43
|
-
## simply.collect.addListener
|
|
44
|
-
|
|
45
|
-
Add a collect listener. See the code above in the overview.
|
|
46
|
-
|
|
47
|
-
## simply.collect.removeListener
|
|
48
|
-
|
|
49
|
-
Removes a previously added listener. You must call removeListener with the
|
|
50
|
-
exact same name and function as used in addListener:
|
|
51
|
-
|
|
52
|
-
```javascript
|
|
53
|
-
simply.collect.removeListener('address', getAddress);
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## simply.collect.update
|
|
57
|
-
|
|
58
|
-
simply.collect only listens for the change event. So if you update an input
|
|
59
|
-
elements value through javascript, the collect listeners won't trigger, unless
|
|
60
|
-
you also trigger the change event. simply.collect.update does this for you:
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
simply.collect.update(form.elements.zipcode, newZipcode);
|
|
64
|
-
```
|