File tree 2 files changed +19
-26
lines changed 2 files changed +19
-26
lines changed Original file line number Diff line number Diff line change @@ -324,10 +324,23 @@ You need to subscribe to a special event in order to know once content has been
324
324
In this repo the subscription is already done in [ onContentSaved.ts] ( src%2Fhelpers%2FonContentSaved.ts )
325
325
326
326
``` ts
327
- epi . subscribe ( " contentSaved" , function ( message : ContentSavedEventArgs ) {
328
- // your code here
327
+ window . addEventListener ( " optimizely:cms: contentSaved" , ( event : any ) => {
328
+ const message = event . detail as ContentSavedEventArgs ;
329
329
});
330
330
```
331
331
332
+ where is defined as following:
333
+
334
+ ``` ts
335
+ interface ContentSavedEventArgs {
336
+ contentLink: string ;
337
+ previewUrl: string ;
338
+ isIndexed: boolean ;
339
+ properties: PropertySaved [];
340
+ parentId? : string ;
341
+ sectionId? : string ;
342
+ }
343
+ ```
344
+
332
345
More details here:
333
346
https://docs.developers.optimizely.com/content-management-system/v1.0.0-CMS-SaaS/docs/enable-live-preview#refresh-the-applications-view-when-content-has-changed
Original file line number Diff line number Diff line change @@ -26,32 +26,12 @@ function isInEditMode() {
26
26
return ! ! getPreviewToken ( ) ;
27
27
}
28
28
29
- function ensureEpiLoaded ( ) {
30
- if ( typeof window !== "undefined" ) {
31
- const epi = ( window as any ) . epi ;
32
- if ( typeof epi !== "undefined" && epi . isEditable && epi . ready ) {
33
- return epi ;
34
- }
35
- } else {
36
- return null ;
37
- }
38
- }
39
-
40
29
export function onContentSaved ( callback : ( ( message : ContentSavedEventArgs ) => void ) ) {
41
30
if ( ! isInEditMode ( ) ) {
42
31
return ;
43
32
}
44
-
45
- const epi = ensureEpiLoaded ( ) ;
46
- if ( epi ) {
47
- console . info ( "successfully connected to CMS." ) ;
48
- epi . subscribe ( "contentSaved" , function ( message : ContentSavedEventArgs ) {
49
- callback ( message ) ;
50
- } ) ;
51
- } else {
52
- setTimeout ( ( ) => {
53
- console . info ( "connecting to CMS..." ) ;
54
- onContentSaved ( callback ) ;
55
- } , 100 ) ;
56
- }
33
+
34
+ window . addEventListener ( "optimizely:cms:contentSaved" , ( event : any ) => {
35
+ callback ( event . detail ) ;
36
+ } ) ;
57
37
}
You can’t perform that action at this time.
0 commit comments