Skip to content

Commit bd8bcca

Browse files
Merge pull request #41 from episerver/feature/use-new-content-events
Use the new content saved events for live preview
2 parents 67bf8bd + 52b29a4 commit bd8bcca

File tree

5 files changed

+29
-61
lines changed

5 files changed

+29
-61
lines changed

samples/music-festival-vue-decoupled/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This project uses:
3737

3838
### On-Page Editing helpers
3939

40-
- [epiBootstrap.js](frontend/src/epiBootstrap.js): registers the `contentSaved` and `epiReady` message handlers that updates the vuex store.
40+
- [livePreview.js](frontend/src/livePreview.js): subscribes to `contentSaved` events to update the vuex store which enabled live preview of content.
4141
- [epiEdit.js](frontend/src/directives/epiEdit.js): a directive that can be added on components to make them optionally editable (e.g. `<span v-epi-edit="Name">`), through `isEditable` and `epiDisableEditing`.
4242
- [EpiProperty.vue](frontend/src/components/EpiProperty.vue): a component that renders a button to edit a property (e.g. `<epi-property property-name="Name">`).
4343

samples/music-festival-vue-decoupled/backend/MusicFestival.Backend.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="EPiServer.CMS" Version="12.32.5" />
11+
<PackageReference Include="EPiServer.CMS" Version="12.33.1" />
1212
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.12.2" />
1313
</ItemGroup>
1414

samples/music-festival-vue-decoupled/frontend/src/epiBootstrap.js

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Sets up subscription to the `contentSaved` event that will update
3+
* the model in the store during editing.
4+
*/
5+
6+
import store from "@/store";
7+
import { parsePreviewToken } from "@/urlHelpers";
8+
import { UPDATE_PREVIEW_TOKEN } from "@/store/modules/epiContext";
9+
import { UPDATE_MODEL_BY_URL } from "@/store/modules/epiDataModel";
10+
11+
window.addEventListener("optimizely:cms:contentSaved", (event) => {
12+
var parsed = parsePreviewToken(event.detail.previewUrl);
13+
store.commit(UPDATE_PREVIEW_TOKEN, parsed.previewToken);
14+
store.dispatch(UPDATE_MODEL_BY_URL, parsed.url);
15+
});
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
import { createApp } from 'vue';
2-
import App from './App.vue';
3-
import EpiEdit from './directives/epiEdit';
4-
import router from './router';
5-
import store from './store';
6-
import './epiBootstrap';
7-
import './assets/styles/main.less';
1+
import { createApp } from "vue";
2+
import App from "./App.vue";
3+
import EpiEdit from "./directives/epiEdit";
4+
import router from "./router";
5+
import store from "./store";
6+
import "./livePreview";
7+
import "./assets/styles/main.less";
88

9-
const app = createApp(App)
10-
.directive('epi-edit', EpiEdit)
11-
.use(store)
12-
.use(router);
9+
const app = createApp(App).directive("epi-edit", EpiEdit).use(store).use(router);
1310

1411
// Register all Optimizely view components globally. This requires webpack!
1512
// Otherwise we need to register all components manually here in main.js.
16-
const requireComponent = require.context('./views', true, /.vue$/);
13+
const requireComponent = require.context("./views", true, /.vue$/);
1714

1815
requireComponent.keys().forEach((fileName) => {
1916
const componentConfig = requireComponent(fileName);
2017

2118
// Gets the component name regardless folder depth
2219
const componentName = fileName
23-
.split('/')
20+
.split("/")
2421
.pop()
25-
.replace(/\.\w+$/, '');
22+
.replace(/\.\w+$/, "");
2623

2724
// Look for the component options on `.default`, which will
2825
// exist if the component was exported with `export default`,
2926
// otherwise fall back to module's root.
3027
app.component(componentName, componentConfig.default || componentConfig);
3128
});
3229

33-
app.mount('#app');
30+
app.mount("#app");

0 commit comments

Comments
 (0)