Skip to content

Instantly share code, notes, and snippets.

@tehmaestro
Last active April 28, 2021 10:19
Show Gist options
  • Save tehmaestro/16647df0bdc19a9b199399b8a08d8023 to your computer and use it in GitHub Desktop.
Save tehmaestro/16647df0bdc19a9b199399b8a08d8023 to your computer and use it in GitHub Desktop.
New Twiddle
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class extends Component {
@service session;
@service myService;
@tracked value;
@tracked count = 0;
@action
setWithMyService() {
this.myService.setData();
this.value = this.session.store._data;
this.count++;
}
@action
setWithSessionThis() {
this.session.setDataWithThis();
this.value = this.session.store._data;
this.count++;
}
@action
setWithSessionSet() {
this.session.setDataWithSet();
this.value = this.session.store._data;
this.count++;
}
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
import Service, { inject as service } from '@ember/service';
import { set } from '@ember/object';
export default class MyService extends Service {
@service session;
setData() {
set(this.session.data, 'setBy', 'myService');
}
}
import Session from 'ember-simple-auth/services/session';
import { set } from '@ember/object';
export default class SessionService extends Session {
setDataWithThis() {
this.set('data.setBy', 'sessionWithThis');
}
setDataWithSet() {
set(this.data, 'setBy', 'sessionWithSet');
}
}
import EphemeralStore from 'ember-simple-auth/session-stores/ephemeral';
export default class ApplicationStorage extends EphemeralStore {
key = 'session';
}
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
<MyComponent />
<br>
<br>
<p>Call count {{this.count}}</p>
<p>Session key set by: {{this.value}}</p>
<button {{on "click" this.setWithMyService}}>Set using my service</button>
<button {{on "click" this.setWithSessionThis}}>Set using session this</button>
<button {{on "click" this.setWithSessionSet}}>Set using session set</button>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0",
"ember-simple-auth": "3.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment