You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An [Ember CLI](https://ember-cli.com/) addon to standardise a common adapter pattern.
3
+
An [Ember CLI](https://ember-cli.com/) addon to standardise a common adapter
4
+
pattern.
4
5
5
-
The adapter pattern helps to provide a common interface from which two incompatible interface may work together. For example you may wish to include in your applications the ability to authenticate users through a variety of social platforms (i.e. Facebook and Twitter). Each platform defines its own API which to interface with it's servers. Using the adapter pattern you can separate the logic of both APIs into their own adapter objects, using a common interface to work with both.
6
+
The adapter pattern helps to provide a common interface from which two
7
+
incompatible interface may work together. For example you may wish to include
8
+
in your applications the ability to authenticate users through a variety of
9
+
social platforms (i.e. Facebook and Twitter). Each platform defines its own API
10
+
which to interface with it's servers. Using the adapter pattern you can
11
+
separate the logic of both APIs into their own adapter objects, using a common
12
+
interface to work with both.
6
13
7
-
This addon implements a common adapter pattern that can be included in any ember object allowing it to act as a proxy between the application and any external interface.
14
+
This addon implements a common adapter pattern that can be included in any
15
+
ember object allowing it to act as a proxy between the application and any
16
+
external interface.
8
17
9
18
## Installation
10
19
@@ -15,13 +24,16 @@ ember install ember-cli-adapter-pattern
15
24
16
25
## Usage
17
26
18
-
This addon implements a mixin that should be included in any object you wish to act as the interface between your application and any external platform or API.
27
+
This addon implements a mixin that should be included in any object you wish to
28
+
act as the interface between your application and any external platform or API.
19
29
20
30
### Adaptable Mixin
21
31
22
-
In order to implement the adapter pattern, it is recommended you include the `Adaptable` mixin into an ember object that will act as a singleton, i.e. a service.
32
+
In order to implement the adapter pattern, it is recommended you include the
33
+
`Adaptable` mixin into an ember object that will act as a singleton, i.e. a
34
+
service.
23
35
24
-
##### <aname="adaptable-example"></a>Example:
36
+
##### Adaptable Example
25
37
26
38
```JavaScript
27
39
// app/services/social.js
@@ -32,7 +44,7 @@ import proxyToAdapter from 'ember-cli-adapter-pattern/utils/proxy-to-adapter';
32
44
exportdefaultEmber.Service.extend(Adaptable, {
33
45
login:proxyToAdapter('login'), // Provides a safe method to proxy your API to each adapter.
This creates a service that will act as the common API for each of your adapters. Here you can see I have defined a single common API method named `login`.
82
+
This creates a service that will act as the common API for each of your
83
+
adapters. Here you can see I have defined a single common API method named
84
+
`login`.
71
85
72
86
### Making API Calls
73
87
74
-
To make calls to your API you must inject the `Adaptable` object into another ember object (i.e. a controller) and invoke it as normal.
88
+
To make calls to your API you must inject the `Adaptable` object into another
89
+
ember object (i.e. a controller) and invoke it as normal.
The action defined in the controller will call the `login` method on the `social` service. This will in turn forward the invocation on to each of the adapters. Of course in this example it would make little sense to login with more than one platform at the same time. If you wish to call only one adapter then you must pass in it's name to the API call.
108
+
The action defined in the controller will call the `login` method on the
109
+
`social` service. This will in turn forward the invocation on to each of the
110
+
adapters. Of course in this example it would make little sense to login with
111
+
more than one platform at the same time. If you wish to call only one adapter
This will only make the API call to the 'Facebook' adapter.
113
132
114
-
Each API call will be wrapped within a promise that resolves with the returned result of the adapter mapped to the adapter name.
133
+
Each API call will be wrapped within a promise that resolves with the returned
134
+
result of the adapter mapped to the adapter name.
115
135
116
136
### ProxyToAdapter Utility
117
137
118
-
The `proxyToAdapter` utility method simply forwards calls made to each of your API methods to all defined adapters, or just a single adapter if specified. It is recommended you use `proxyToAdapter` because it implements guard statements to prevent the application from throwing errors.
138
+
The `proxyToAdapter` utility method simply forwards calls made to each of your
139
+
API methods to all defined adapters, or just a single adapter if specified. It
140
+
is recommended you use `proxyToAdapter` because it implements guard statements
141
+
to prevent the application from throwing errors.
119
142
120
-
If however you need to extend the functionality of your API methods then somewhere in its implementation it needs to call the `invoke` method defined within the `Adaptable` mixin.
143
+
If however you need to extend the functionality of your API methods then
144
+
somewhere in its implementation it needs to call the `invoke` method defined
0 commit comments