Skip to content

Commit

Permalink
feat: upgrade to bridge v2
Browse files Browse the repository at this point in the history
  • Loading branch information
BJvdA committed May 4, 2021
1 parent 0946138 commit 8a7bac6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- beta
jobs:
release:
name: Release
Expand Down
24 changes: 7 additions & 17 deletions src/bridge/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Story } from '../story';
const loadBridge = (callback: () => void) => {
if (!window.storyblok) {
const script = document.createElement('script');
script.src = `//app.storyblok.com/f/storyblok-latest.js`;
script.src = `//app.storyblok.com/f/storyblok-v2-latest.js`;
script.onload = callback;
document.body.appendChild(script);
} else {
Expand All @@ -18,26 +18,16 @@ export const init = (
resolveRelations: string[] = [],
) => {
loadBridge(() => {
if (window.storyblok) {
window.storyblok.init({ accessToken: token });
if (window.StoryblokBridge) {
window.storyblok = new window.StoryblokBridge({
// accessToken: token,
resolveRelations,
});

// Update story on input in Visual Editor
// this will alter the state and replaces the current story with a
// current raw story object and resolve relations
window.storyblok.on('input', (event) => {
if (event.story.content.uuid === story?.content?.uuid) {
event.story.content = window.storyblok.addComments(
event.story.content,
event.story.id,
);

window.storyblok.resolveRelations(
event.story,
resolveRelations,
() => {
onStoryInput(event.story);
},
);
onStoryInput(event.story);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ declare global {
}
interface Window {
storyblok: StoryblokBridge;
StoryblokBridge: any;
StoryblokCacheVersion: number;
}
}
Expand Down

0 comments on commit 8a7bac6

Please sign in to comment.