mirror of
https://github.com/hydra-synth/hydra.git
synced 2026-06-16 04:26:10 +02:00
update url when code is evaluated
This commit is contained in:
@@ -9,7 +9,7 @@ export default function editorStore(state, emitter) {
|
||||
} else {
|
||||
editor.mutator.mutate({ reroll: false, changeTransform: evt.metaKey });
|
||||
editor.formatCode()
|
||||
emitter.emit('gallery: save locally', editor.getValue())
|
||||
emitter.emit('gallery: save to URL', editor.getValue())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -31,7 +31,7 @@ export default function editorStore(state, emitter) {
|
||||
// })
|
||||
emitter.emit('repl: eval', code, (string, err) => {
|
||||
editor.flashCode()
|
||||
if (!err) emitter.emit('gallery: save locally', code)
|
||||
if (!err) emitter.emit('gallery: save to URL', code)
|
||||
// sketches.saveLocally(code)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -93,10 +93,10 @@ export default async function store(state, emitter) {
|
||||
emitter.on('extensions: load example', (extensionIndex, exampleIndex) => {
|
||||
const {categories, selectedCategoryIndex } = state.extensions
|
||||
const path = categories[selectedCategoryIndex].entries[extensionIndex].examples[exampleIndex]
|
||||
const url = new URL(path);
|
||||
console.log(url)
|
||||
const newURL= new URL(path);
|
||||
console.log(newURL, state.gallery)
|
||||
|
||||
state.gallery.setSketchFromURL(url.search, (code) => {
|
||||
state.gallery.setSketchFromURL(newURL.search, (code) => {
|
||||
emitter.emit('load and eval code', code)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ export default function galleryStore(state, emitter) {
|
||||
emitter.on('DOMContentLoaded', function () {
|
||||
|
||||
sketches = new Gallery((code, sketchFromURL) => {
|
||||
emitter.emit('load and eval code', code)
|
||||
emitter.emit('load and eval code', code, false)
|
||||
if(sketchFromURL) {
|
||||
emitter.emit('ui: hide info')
|
||||
} else {
|
||||
@@ -20,14 +20,14 @@ export default function galleryStore(state, emitter) {
|
||||
})
|
||||
|
||||
// redundant with below
|
||||
emitter.on('gallery:saveToURL', function () {
|
||||
let editor = state.editor.editor
|
||||
const editorText = editor.getValue()
|
||||
sketches.saveLocally(editorText)
|
||||
})
|
||||
// emitter.on('gallery:saveToURL', function () {
|
||||
// let editor = state.editor.editor
|
||||
// const editorText = editor.getValue()
|
||||
// sketches.saveLocally(editorText)
|
||||
// })
|
||||
|
||||
// save to url
|
||||
emitter.on('gallery: save locally', function (code) {
|
||||
emitter.on('gallery: save to URL', function (code) {
|
||||
// let editor = state.editor.editor
|
||||
// const editorText = editor.getValue()
|
||||
sketches.saveLocally(code)
|
||||
|
||||
+2
-1
@@ -11,9 +11,10 @@ export default function store(state, emitter) {
|
||||
state.serverURL = SERVER_URL !== undefined ? SERVER_URL : null
|
||||
|
||||
|
||||
emitter.on('load and eval code', (code) => {
|
||||
emitter.on('load and eval code', (code, shouldUpdateURL = true) => {
|
||||
emitter.emit('editor: load code', code)
|
||||
emitter.emit('repl: eval', code)
|
||||
if(shouldUpdateURL) emitter.emit('gallery: save to URL', code)
|
||||
})
|
||||
|
||||
emitter.on('repl: eval', (code = '', callback) => {
|
||||
|
||||
@@ -41,6 +41,8 @@ export default class Editor extends EventEmitter {
|
||||
this.emit(e, this)
|
||||
} else if (e === 'editor:formatCode') {
|
||||
this.formatCode()
|
||||
} else if (e == 'gallery:saveToURL') {
|
||||
this.emit('editor: save to URL', this.cm.getValue())
|
||||
} else {
|
||||
this.emit(e, this)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user