Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto-bound methods #326

Merged
merged 1 commit into from
Jul 27, 2021
Merged

feat: auto-bound methods #326

merged 1 commit into from
Jul 27, 2021

Conversation

buschtoens
Copy link
Owner

Example using the {{pick}} helper from ember-composable-helpers to get the event.target.checked property.

<label>
  Enable dark mode
  <input
    type="checkbox"
    checked={{get (service "theme") "isDark"}}
    {{on "input" (pick "target.checked" (service "theme" "toggleDarkMode"))}}
  >
</label>
export default class ThemeService extends Service {
  @tracked isDark = false;

  toggleDarkMode(newValue = !this.isDark) {
    // Even though this method isn't using `@action`, the `{{service}}` helper
    // binds it to the service instance.
    this.isDark = newValue;
  }
}

@buschtoens buschtoens merged commit 1043b60 into main Jul 27, 2021
@buschtoens buschtoens deleted the feat-method branch July 27, 2021 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant