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
f5ce9620
Commit
f5ce9620
authored
Nov 02, 2016
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update angular.js integration example.
parent
fa338c48
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
docs/source/other_frameworks.rst
docs/source/other_frameworks.rst
+21
-10
No files found.
docs/source/other_frameworks.rst
View file @
f5ce9620
Integrating converse
.
js into other frameworks
Integrating converse
i
js into other frameworks
=============================================
Angular.js
...
...
@@ -8,7 +8,7 @@ Angular.js has the concept of a `service <https://docs.angularjs.org/guide/servi
which is a special kind of `provider <https://docs.angularjs.org/guide/providers>`_.
An angular.js service is a constructor or object which provides an API defined by the
write
r of the service. The goal of a service is to organize and share code, so
autho
r of the service. The goal of a service is to organize and share code, so
that it can be used across an application.
So, if we wanted to properly integrate converse.js into an angular.js
...
...
@@ -16,7 +16,7 @@ application, then putting it into a service is a good approach.
This lets us avoid having a global ``converse`` API object (accessible via
``windows.converse``), and instead we can get hold of the converse API via
angular
.j
s dependency injection, when we specify it as a dependency for our
angular
'
s dependency injection, when we specify it as a dependency for our
angular components.
Below is an example code that wraps converse.js as an angular.js service.
...
...
@@ -24,16 +24,27 @@ Below is an example code that wraps converse.js as an angular.js service.
.. code-block:: javascript
angular.module('converse', []).service('converse', function() {
var deferred = new $.Deferred(),
promise = deferred.promise();
// We create three promises, which will be resolved at various times
var loaded_deferred = new $.Deferred(), // Converse.js has been loaded
connected_deferred = new $.Deferred(), // An XMPP connection has been established
roster_deferred = new $.Deferred(); // The contacts roster has been fetched.
var loaded_promise = loaded_deferred.promise(),
connected_promise = connected_deferred.promise(),
roster_promise = roster_deferred.promise();
// This is the API of the service.
var service = {
'
load': _.constant(
promise),
'
waitUntilLoaded': _.constant(loaded_
promise),
'initialize': function initConverse(options) {
this.load().done(_.partial(this.api.initialize, options));
}
this.waitUntilLoaded().done(_.partial(this.api.initialize, options));
},
'waitUntilConnected': _.constant(connected_promise),
'waitUntilRosterFetched': _.constant(roster_promise),
};
// Here we define the core components of converse.js that will be
// loaded and used.
define("converse", [
"converse-api",
// START: Removable components
...
...
@@ -93,7 +104,7 @@ your components, for example:
// Your custom code can come here..
// Then when you're ready, you can initialize converse.js
converse.
loa
d().done(function () {
converse.
waitUntilLoade
d().done(function () {
converse.initialize({
'allow_logout': false,
'auto_login': 'true',
...
...
@@ -108,7 +119,7 @@ your components, for example:
});
});
You might have noticed the ``
loa
d()`` method being called on the ``converse``
You might have noticed the ``
waitUntilLoade
d()`` method being called on the ``converse``
service. This is a special method added to the service (see the implementation
example above) that makes sure that converse.js is loaded and available. It
returns a jQuery promise which resolves once converse.js is available.
...
...
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