@@ -14,6 +14,62 @@ Ember Custom Actions is a package for defining custom API actions, dedicated for
14
14
15
15
## Documentation
16
16
17
+ ### Model actions
18
+ To define custom action like: ` posts/1/publish ` you can use
19
+ ` modelAction(path, options) ` method with arguments:
20
+ - ` path ` - the url of the action (in our case it's ` publish ` )
21
+ - ` options ` - optional parameter which will overwrite the configuration options
22
+
23
+ ``` js
24
+ import Model from ' ember-data/model' ;
25
+ import { modelAction } from ' ember-custom-actions' ;
26
+
27
+ export default Model .extend ({
28
+ publish: modelAction (' publish' , { pushToStore: false }),
29
+ });
30
+
31
+ ```
32
+
33
+ #### Usage
34
+ ``` js
35
+ let user = this .get (' currentUser' );
36
+ let postToPublish = this .get (' store' ).findRecord (' post' , 1 );
37
+ let payload = { publisher: user };
38
+
39
+ postToPublish .publish (payload).then ((status ) => {
40
+ alert (` Post has been: ${ status} ` )
41
+ });
42
+ ```
43
+
44
+ ### Resource actions
45
+ To a define custom action like: ` posts/favorites ` you can use
46
+ ` resourceAction(path, options) ` method with arguments:
47
+ - ` path ` - the url of the action (in our case it's ` favorites ` )
48
+ - ` options ` - optional parameter which will overwrite the configuration options
49
+
50
+ ``` js
51
+ import Model from ' ember-data/model' ;
52
+ import { resourceAction } from ' ember-custom-actions' ;
53
+
54
+ export default Model .extend ({
55
+ favorites: resourceAction (' favorites' , { type: ' GET' }),
56
+ });
57
+
58
+ ```
59
+
60
+ #### Usage
61
+ ``` js
62
+ let user = this .get (' currentUser' );
63
+ let emptyPost = this .get (' store' ).createRecord (' post' );
64
+ let payload = { user };
65
+
66
+ emptyPost .favorites (payload).then ((favoritesPosts ) => {
67
+ console .log (favoritesPosts);
68
+ }).finally (()=> {
69
+ emptyPost .deleteRecord ();
70
+ });
71
+ ```
72
+
17
73
### Configuration
18
74
19
75
You can define your custom options in your ` config/environment.js ` file
@@ -77,63 +133,6 @@ It's great for API with request data format restrictions
77
133
- decamelize
78
134
- underscore
79
135
80
-
81
- ### Model actions
82
- To define custom action like: ` posts/1/publish ` you can use
83
- ` modelAction(path, options) ` method with arguments:
84
- - ` path ` - the url of the action (in our case it's ` publish ` )
85
- - ` options ` - optional parameter which will overwrite the configuration options
86
-
87
- ``` js
88
- import Model from ' ember-data/model' ;
89
- import { modelAction } from ' ember-custom-actions' ;
90
-
91
- export default Model .extend ({
92
- publish: modelAction (' publish' , { pushToStore: false }),
93
- });
94
-
95
- ```
96
-
97
- #### Usage
98
- ``` js
99
- let user = this .get (' currentUser' );
100
- let postToPublish = this .get (' store' ).findRecord (' post' , 1 );
101
- let payload = { publisher: user };
102
-
103
- postToPublish .publish (payload).then ((status ) => {
104
- alert (` Post has been: ${ status} ` )
105
- });
106
- ```
107
-
108
- ### Resource actions
109
- To a define custom action like: ` posts/favorites ` you can use
110
- ` resourceAction(path, options) ` method with arguments:
111
- - ` path ` - the url of the action (in our case it's ` favorites ` )
112
- - ` options ` - optional parameter which will overwrite the configuration options
113
-
114
- ``` js
115
- import Model from ' ember-data/model' ;
116
- import { resourceAction } from ' ember-custom-actions' ;
117
-
118
- export default Model .extend ({
119
- favorites: resourceAction (' favorites' , { type: ' GET' }),
120
- });
121
-
122
- ```
123
-
124
- #### Usage
125
- ``` js
126
- let user = this .get (' currentUser' );
127
- let emptyPost = this .get (' store' ).createRecord (' post' );
128
- let payload = { user };
129
-
130
- emptyPost .favorites (payload).then ((favoritesPosts ) => {
131
- console .log (favoritesPosts);
132
- }).finally (()=> {
133
- emptyPost .deleteRecord ();
134
- });
135
- ```
136
-
137
136
# Development
138
137
139
138
## Installation
0 commit comments