Created
April 26, 2018 22:51
-
-
Save kylefox/fdae80f6199499428a4740f241eb6783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus" | |
class PageSectionFormController extends Controller { | |
initialize() { | |
this.sectionID = parseInt(this.element.getAttribute("data-page-section-id")) | |
this.preview = this.application.getControllerForElementAndIdentifier( | |
document.querySelector(`[data-controller="rich-text-preview"][data-page-section-id="${this.sectionID}"]`), | |
'rich-text-preview', | |
); | |
} | |
updatePreview() { | |
this.preview.update(this.getData()); | |
} | |
saveChanges() { | |
console.log('\nsaveChanges:') | |
console.log(`=> data: ${JSON.stringify(this.getData())}`); | |
} | |
onChange() { | |
this.updatePreview(); | |
this.saveChanges() | |
} | |
getData() { | |
return { | |
id: this.sectionID, | |
content: this.getContent() | |
}; | |
} | |
} | |
export default PageSectionFormController; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PageSectionFormController from "./page_section_form_controller" | |
export default class extends PageSectionFormController { | |
static targets = [ 'heading', 'text' ] | |
getContent() { | |
return { | |
heading: this.headingTarget.value, | |
text: this.textTarget.value, | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus" | |
export default class extends Controller { | |
static targets = [ 'heading', 'text' ] | |
update(data) { | |
this.headingTarget.innerHTML = data.content.heading; | |
this.textTarget.innerHTML = data.content.text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I love how there is no jQuery in this code 👍
Looks fun to work with