Skip to content

Commit

Permalink
Added support for signalling content changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed Feb 23, 2019
1 parent 8219d8c commit d96a25c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
20 changes: 19 additions & 1 deletion module/api.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import * as contentflow from 'content-flow'
import * as $ from 'manhattan-essentials'


export class FlowAPI extends contentflow.BaseAPI {

constructor(baseURL='/', baseParams={}) {
constructor(baseURL='/', baseParams={}, updateSignalKey=null) {
super(baseURL, baseParams)

this._updateSignalKey = updateSignalKey
}

_callEndpoint(method, endpoint, params={}) {
const response = super._callEndpoint(method, endpoint, params)

// Signal that a content update may have occurred
if (method.toLowerCase() !== 'get') {
$.dispatch(
window,
'contentupdatesignalled',
{'key': this._updateSignalKey}
)
}

return response
}

}
43 changes: 41 additions & 2 deletions module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ function defineSaveProcess(url, params, lock, contentFunc) {

// -- Initializer --

export function init(baseURL='/', baseFlowURL='/', baseParams={}) {
export function init(
baseURL='/',
baseFlowURL='/',
baseParams={},
updateSignalKey=null
) {

// Set-up the editor and flow manager
const editor = contenttools.EditorApp.get()
Expand Down Expand Up @@ -169,7 +174,14 @@ export function init(baseURL='/', baseFlowURL='/', baseParams={}) {
)

// Initialize the page flow manager
flowMgr.init('[data-cf-flow]', new FlowAPI(baseFlowURL, baseParams))
flowMgr.init(
'[data-cf-flow]',
new FlowAPI(
baseFlowURL,
baseParams,
updateSignalKey
)
)

// Create an element in which manhattan specific UI elements should be
// rooted.
Expand Down Expand Up @@ -238,4 +250,31 @@ export function init(baseURL='/', baseFlowURL='/', baseParams={}) {
)
)

if (updateSignalKey) {

// Set up content update signalling for related tabs
editor.addEventListener(
'saved',
() => {
$.dispatch(
window,
'contentupdatesignalled',
{'key': updateSignalKey}
)
}
)

$.listen(
window,
{
'contentupdatesignalled': (event) => {
// Signal a contentchange to any other tabs listening
localStorage.setItem(event.key, Date.now())
}
}
)
}

}


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "manhattan-content",
"version": "1.0.0-beta.3",
"version": "1.0.0-beta.4",
"description": "Content editing for the manhattan web framework",
"engines": {
"node": ">=8.9.4"
Expand Down

0 comments on commit d96a25c

Please sign in to comment.