Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
994c961d
Commit
994c961d
authored
Feb 14, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a `waitUntil` API for promises.
parent
1a0cb070
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
2 deletions
+67
-2
docs/CHANGES.md
docs/CHANGES.md
+1
-0
docs/source/developer_api.rst
docs/source/developer_api.rst
+41
-1
src/converse-api.js
src/converse-api.js
+7
-0
src/converse-core.js
src/converse-core.js
+18
-1
No files found.
docs/CHANGES.md
View file @
994c961d
...
...
@@ -9,6 +9,7 @@
-
Use lodash instead of underscore.js [jcbrand]
-
Improved roster filter UX. [jcbrand]
-
Render the login form again upon authfail. [jcbrand]
-
New promises API:
[
waitUntil
](
https://conversejs.org/docs/html/developer_api.html#waituntil
)
[
jcbrand
]
-
#770 Allow setting contact attrs on chats.open [Ape]
## 2.0.6 (2017-02-13)
...
...
docs/source/developer_api.rst
View file @
994c961d
.. raw:: html
<div id="banner"><a href="https://github.com/jcbrand/converse.js/blob/master/docs/source/theming.rst">Edit me on GitHub</a></div>
=============================
The converse.js developer API
=============================
...
...
@@ -84,6 +84,7 @@ Example:
roster_groups: true
});
The **plugin** grouping
------------------------
...
...
@@ -164,6 +165,44 @@ For example, to send a message stanza:
});
.. _`waituntil-grouping`:
waitUntil
---------
This method can be used to wait for promises. Promises are similar to events
(for event handling, refer to the :ref:`listen-grouping`), but they differ in
two important ways:
* A promise gets resolved only once, whereas events can fire multiple times.
* A handler registered for a promise, will still fire *after* the promise has
been resolved, which is not the case with an event handler.
Converse.js has the following promises:
* cachedRoster
* chatBoxesFetched
* connected
* pluginsInitialized
* roster
* rosterContactsFetched
* rosterGroupsFetched
* rosterInitialized
* statusInitialized
Below is an example from `converse-muc.js <https://github.com/jcbrand/converse.js/blob/master/src/converse-muc.js>`_
where the `rosterContactsFetched` promise is waited on. The method
`this.initInviteWidget` will initialize the chatroom invitation widget.
.. code-block:: javascript
_converse.api.waitUntil('rosterContactsFetched').then(this.initInviteWidget.bind(this));
The line above executes only once a chatroom has been opened and entered, so
using an event handler here would not work, since the event might have fired
already by that time.
The **archive** grouping
------------------------
...
...
@@ -982,3 +1021,4 @@ grouping:
.. code-block:: javascript
_converse.listen.not('message', function (messageXML) { ... });
src/converse-api.js
View file @
994c961d
...
...
@@ -180,6 +180,13 @@
);
},
},
'
waitUntil
'
:
function
(
name
)
{
var
promise
=
_converse
.
promises
[
name
];
if
(
_
.
isUndefined
(
promise
))
{
return
null
;
}
return
_converse
.
promises
[
name
].
promise
();
},
'
send
'
:
function
(
stanza
)
{
_converse
.
connection
.
send
(
stanza
);
},
...
...
src/converse-core.js
View file @
994c961d
...
...
@@ -47,7 +47,24 @@
var
_converse
=
{};
_converse
.
templates
=
{};
_
.
extend
(
_converse
,
Backbone
.
Events
);
_converse
.
emit
=
_converse
.
trigger
;
_converse
.
promises
=
{
'
cachedRoster
'
:
new
$
.
Deferred
(),
'
chatBoxesFetched
'
:
new
$
.
Deferred
(),
'
connected
'
:
new
$
.
Deferred
(),
'
pluginsInitialized
'
:
new
$
.
Deferred
(),
'
roster
'
:
new
$
.
Deferred
(),
'
rosterContactsFetched
'
:
new
$
.
Deferred
(),
'
rosterGroupsFetched
'
:
new
$
.
Deferred
(),
'
rosterInitialized
'
:
new
$
.
Deferred
(),
'
statusInitialized
'
:
new
$
.
Deferred
()
};
_converse
.
emit
=
function
(
name
)
{
_converse
.
trigger
.
apply
(
this
,
arguments
);
var
promise
=
_converse
.
promises
[
name
];
if
(
!
_
.
isUndefined
(
promise
))
{
promise
.
resolve
();
}
};
_converse
.
core_plugins
=
[
'
converse-bookmarks
'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment