Giter VIP home page Giter VIP logo

Comments (8)

dgavey avatar dgavey commented on May 29, 2024 2

@ELepolt You have to use the @action decorator for your this.verifyToken function in the component class or else this === undefined

Example

@action
verifyToken(token) {
  console.log(this) //Works
} ```

from ember-render-modifiers.

ELepolt avatar ELepolt commented on May 29, 2024 1

#OctaneWoes. Thank you so much.

from ember-render-modifiers.

jenweber avatar jenweber commented on May 29, 2024

cc @rwjblue this was opened at your suggestion following some chat in octane-migration.

from ember-render-modifiers.

ELepolt avatar ELepolt commented on May 29, 2024

Hey all. Just came upon this today. Is there a more proper way to access this inside of a component?

// component.hbs
<Input @type="text" @value={{@token}} {{did-insert this.verifyToken @token}}/>

// component.js
verifyToken(token) {
  console.log(this) // logs 'undefined'
}

Am I misinterpreting how this addon should be used?

from ember-render-modifiers.

tniezurawski avatar tniezurawski commented on May 29, 2024

One thing that I've learned here that someone can make use of is this.set() a value. Even with @action I've got an error: TypeError: this.set is not a function.

In my case, I had to save a reference to a node and solved that by using set from @ember/object:

{{!-- template.hbs --}}

<div {{did-insert this.setFileRef}}>
  <div id="selector"></div>
</div>
// component.js

import Component from '@glimmer/component';
- import { action } from '@ember/object';
+ import { action, set } from '@ember/object';

export default class SomeComponent extends Component {
  @action
  setFileRef() {
-    this.set('fieldRef', document.querySelector('#selector'));
+    set(this, 'fieldRef', document.querySelector('#selector'));
  }
}

That might not be the best example because in this case {{ref}} in nicer. But I'll leave it here anyway.

from ember-render-modifiers.

dgavey avatar dgavey commented on May 29, 2024

@tniezurawski You don't need to use set in a glimmer component, in fact it's not recommended.

Also, you can do this code differently here. As a modifier passes in the element it's attached to so instead of looking through the whole document you can look just within this component.

@action
  setFileRef(element) {
    this.fieldRef =  element.querySelector('#selector'));
  }

from ember-render-modifiers.

tniezurawski avatar tniezurawski commented on May 29, 2024

@dgavey Oh, nice! Thanks for the explanation!

from ember-render-modifiers.

mcfiredrill avatar mcfiredrill commented on May 29, 2024

Anyone have a hint on where I could go about adding this ?
Maybe here? https://github.com/emberjs/ember-render-modifiers/blob/master/addon/modifiers/did-insert.js#L61
How could I check that it's an action and not a regular function?

from ember-render-modifiers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.