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

Documentation for wildcard events #299

Merged
merged 29 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9f239db
documentation for wildcard events
thomasarbona May 27, 2019
1f05f5d
add mqtt dependency
thomasarbona May 28, 2019
c149bec
Merge branch '3-dev' into KZL-291-wildcarded-event
scottinet Jun 4, 2019
469c026
Merge branch '3-dev' into KZL-291-wildcarded-event
thomasarbona Jun 5, 2019
a8a8407
fix arborescence
thomasarbona Jun 5, 2019
16a4932
fix mqtt dependency
thomasarbona Jun 5, 2019
b1a5fe8
Merge branch 'KZL-291-wildcarded-event' of https://github.com/kuzzlei…
thomasarbona Jun 5, 2019
7fd88b7
fix naming template
thomasarbona Jun 5, 2019
5552edb
clean sorting utils + fix wildcard events params type
thomasarbona Jun 5, 2019
8008176
Merge branch '3-dev' into KZL-291-wildcarded-event
thomasarbona Jun 5, 2019
30a4092
Merge branch '3-dev' into KZL-291-wildcarded-event
alexandrebouthinon Jun 5, 2019
6cd9d7a
Merge branch '3-dev' into KZL-291-wildcarded-event
Yoann-Abbes Jun 5, 2019
5277712
merge + suggestions
thomasarbona Jun 11, 2019
e81a573
Fix package-lock.json
alexandrebouthinon Jun 11, 2019
a7a3244
Merge branch '3-dev' into KZL-291-wildcarded-event
xbill82 Jun 11, 2019
55fc156
Merge branch '3-dev' into KZL-291-wildcarded-event
Yoann-Abbes Jun 11, 2019
519adfc
Merge branch '3-dev' into KZL-291-wildcarded-event
Aschen Jun 11, 2019
56466b0
Merge branch '3-dev' into KZL-291-wildcarded-event
xbill82 Jun 12, 2019
e539e38
Merge branch '3-dev' into KZL-291-wildcarded-event
Aschen Jun 12, 2019
b7d6a31
delete mqtt dependency
thomasarbona Jun 12, 2019
e1bd1ac
Merge branch 'KZL-291-wildcarded-event' of https://github.com/kuzzlei…
thomasarbona Jun 12, 2019
8fd40b2
Merge branch '3-dev' into KZL-291-wildcarded-event
Yoann-Abbes Jun 12, 2019
7b1d78f
Merge branch '3-dev' into KZL-291-wildcarded-event
scottinet Jun 12, 2019
1e933a1
Update src/core/1/plugins/guides/events/wildcard-events/index.md
xbill82 Jun 12, 2019
94c8ac4
Merge branch '3-dev' into KZL-291-wildcarded-event
xbill82 Jun 12, 2019
39df911
unstage package-lock.json + fix snippets wording
thomasarbona Jun 12, 2019
99fa98b
Merge branch 'KZL-291-wildcarded-event' of https://github.com/kuzzlei…
thomasarbona Jun 12, 2019
d1cf84c
[merge] restored package-lock.json
xbill82 Jun 12, 2019
de97917
Disabled Java and C++ tests from local execution
xbill82 Jun 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"js-cookie": "^2.1.4",
"lunr": "^2.3.6",
"moment": "^2.24.0",
"mqtt": "^3.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests failed because mqtt dependency is missing

Copy link
Contributor

@scottinet scottinet Jun 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the effort and checked: that module is indeed used by the Javascript IoT guide.

  1. this change should appear in your PR description: without it, it's impossible for reviewers to get why this module has been added
  2. the package-lock.json file must also be updated (with an up-to-date version of the npm CLI).
  3. since this is only used to test the documentation, then that module must be installed in the devDependencies part of the package.json file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it should be removed from this project's package.json file.

"node-sass": "^4.11.0",
"prompt-confirm": "^2.0.4",
"read-yaml": "^1.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/.vuepress/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ function sortPagesByOrderAndTitle(p1, p2) {
const o1 = get(p1, 'frontmatter.order', null);
const o2 = get(p2, 'frontmatter.order', null);

if ((o1 === null || typeof o1 === 'undefined') && o2) {
if ((o1 === null || typeof o1 === 'undefined') && !isNaN(o2)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if o1 or o2 is NaN, then that function returns 1 (because any comparison operation on a NaN value ends up returning false)

also, I don't get the purpose of that test, what does it do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both if serve to check if o1 and o2 are valids. I added !isNaN() because without that, if o1 or o2 equals to zero, the sorting is broken

Copy link
Contributor

@scottinet scottinet Jun 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it, because NaN is not 0

(and what do you mean by broken?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When o2 is equal to zero, the condition consider that o2 is not a valid number. This produce broken sorting of pages because a page with order set to zero wasn't the first page in the list

return 1;
}
if ((o2 === null || typeof o2 === 'undefined') && o1) {
if ((o2 === null || typeof o2 === 'undefined') && !isNaN(o1)) {
return -1;
}
if (o1 === o2) {
Expand Down
86 changes: 86 additions & 0 deletions src/core/1/plugins/plugins/events/wildcard-events/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
type: page
code: false
title: Wildcard Events
order: 250
---

# Wildcard Events

Kuzzle allows you to listen to multiple events with a single listener thanks to wildcards (`*`).

---

## Single wildcard
xbill82 marked this conversation as resolved.
Show resolved Hide resolved

| Arguments | Type | Description |
| --------- | -------------------------------------------------------------- | -------------------------- |
| `request` | <pre><a href=/plugins/1/constructors/request>Request</a></pre> | The normalized API request |
xbill82 marked this conversation as resolved.
Show resolved Hide resolved

With a single wildcard you can listen to all the events triggered by Kuzzle.

#### Example

```javascript
this.pipes =
// listener function will be triggered at each event
'*': <function to call>
};
```

---

## Name wildcard

| Arguments | Type | Description |
| --------- | -------------------------------------------------------------- | -------------------------- |
| `request` | <pre><a href=/plugins/1/constructors/request>Request</a></pre> | The normalized API request |

You can also use wildcards to replace only the name of an event.

### Naming Template

The event name is built using the following template:
xbill82 marked this conversation as resolved.
Show resolved Hide resolved

`<controller>:*`

- `controller`: API controller name

#### Example

```javascript
this.pipes =
// listener function will trigger at each
// events triggered in the document namespace
'document:*': <function to call>
};
```

---

## Templated events wildcard

| Arguments | Type | Description |
| --------- | -------------------------------------------------------------- | -------------------------- |
| `request` | <pre><a href=/plugins/1/constructors/request>Request</a></pre> | The normalized API request |

Wildcards permit listenening templated events.

### Naming Template

The event name is built using the following template:

`<controller>:<template>*`

- `controller`: API controller name
- `template`: `before`, `after` or `error`

#### Example

```javascript
this.pipes =
// listener function will trigger after each
// events triggered in the document namespace
'document:after*': <function to call>
};
```