JSn1nj4 / ElliotDerhay.com

My personal website project.
MIT License
0 stars 1 forks source link

Check for unsaved changes before navigation (#156) #161

Closed JSn1nj4 closed 4 months ago

JSn1nj4 commented 9 months ago

Starting use cases

Implementation

Sample reporter implementation

function reportDirty(hashVal, isDirty) {
  dispatchEvent(new CustomEvent('reportDirtyState', {detail: {hashVal, isDirty}})
}

function checkDirty(hashVal, emitBack) {
  dispatchEvent(new CustomEvent('checkDirtyState', {detail: {hashVal, emitBack}})
}

function receiver({detail: {isDirty}}) {
  console.info(`isDirty: ${isDirty}`)
  // some kind of usage here
}

function forgetDirty(hashVal) {
  dispatchEvent(new CustomEvent('forgetDirtyState', {detail: {hashVal}}))
}

let receiveEvent = 'reporter:receive'
window.addEventListener(receiveEvent, receiver)

Fixes #156

JSn1nj4 commented 4 months ago

Not happening