question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about onremove

See original GitHub issue

You guys are probably getting tired of me asking silly questions. 😃 I’m creating an Ace interop example for a presentation and not seeing the onremove fire when removing DOM elements… I’m thinking I need to somehow properly dispose of Ace. Here’s my code.

const AceComponent = ({ model, actions}) => {  
 
    const css = {
        height: "200px", 
        width: "800px",
        marginTop: "20px",
        marginBottom: "20px"
    }
  
    const setupEditor = (e) => {
        const editor = ace.edit(e);
        editor.setTheme("ace/theme/cobalt");
        editor.getSession().setMode("ace/mode/javascript");
        editor.setValue(model.editorText, 1);
        editor.getSession().on('change', _ => actions.setEditorText(editor.getSession().getValue()))                               
    }
    
    const disposeEditor = (e) => {
        console.log("dispose editor?");
        // ace.editor(e).destroy(),
    }
    
    return (
      <div>
          <div style={css} oncreate={setupEditor} onremove={disposeEditor}></div>
          <div>{ model.editorText }</div>
      </div>
    )
}

app({ 
  model: {
    showEditor: true,
    editorText: "// welcome to the ace editor \rconsole.log(\"hyperapp is the bee's knees!\");"
  },
  reducers: { 
    setEditorText: (model, text) => ({ editorText: text }),
    toggleEditor: (model) => ({showEditor: !model.showEditor})
  },
  view: (model, actions) => (
      <div>
          <input type="button" value="toggle editor" onclick={ _ => actions.toggleEditor() } />
          { model.showEditor && (<AceComponent model={model} actions={actions}></AceComponent>)}          
      </div>
   )  
})

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
cdeutmeyercommented, Feb 26, 2017

I think that from the perspective of a HyperApp end user, it seems reasonable that when the element “goes away” that onremove would then be called.

1reaction
jorgebucarancommented, Feb 27, 2017

@cdeutmeyer Sorry, I meant this as a general question, what I am trying to ask is: why would one need to use onremove?

The only thing I think I would ever need it for is proper disposal of 3rd party libraries like the example above using Ace.

Exactly, why is this necessary? JavaScript has GC, or if you are toggling the editor, then you can call your disposeResources() function or similar inside that toggle effect.

Am I making sense?

Read more comments on GitHub >

github_iconTop Results From Across the Web

onRemove()-event? - javascript - Stack Overflow
I'm not trying to add a handler to the array itself, but to the DOM element (input) so that the input itself can...
Read more >
Leaflet onRemove Control - GIS Stack Exchange
Leaflet onRemove Control · 0 · Know someone who can answer? Share a link to this question via email, Twitter, or Facebook. ·...
Read more >
Table onRemove - node removed from model but not context
Hello, I am having an issue where if I remove a node a from table in UI it is not reflect in my...
Read more >
onDelete action not working through ef6 - Microsoft Q&A
my WPF Application language is c# and used Entity Framework 6 and I have a SQLite database that one of tables has Foreignkey...
Read more >
RE: How to use onRemove() in Liferay Autofields? - Forums
I need to use the Liferay auto-fields to add a question block. ... 2) onRemove: function() { alert('The last field was removed.'); }...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found