Skip to content

Instantly share code, notes, and snippets.

@cromwellryan
Created September 30, 2020 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cromwellryan/c98a328caf9a1e97cf123a4e082fe37f to your computer and use it in GitHub Desktop.
Save cromwellryan/c98a328caf9a1e97cf123a4e082fe37f to your computer and use it in GitHub Desktop.
Range Component on 3.12
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class extends Component {
@tracked
startDate
@tracked
endDate
constructor(owner, {startDate, endDate}) {
super(...arguments)
this.startDate = startDate;
this.endDate = endDate;
}
@action
go() {
const startAsNumber = parseInt(this.startDate);
const endAsNumber = parseInt(this.endDate);
if (startAsNumber >= endAsNumber) return;
this.args.onRangeChanged({
startDate: this.startDate,
endDate: this.endDate
});
}
}
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@tracked
rangeMessage
@action
refreshData({ startDate, endDate }) {
this.rangeMessage = `Showing data for ${startDate} thru ${endDate}`;
}
}
<h1>{{this.rangeMessage}}</h1>
<br>
<br>
<UsageDateRangeSelector @startDate="1" @endDate="3" @onRangeChanged={{action "refreshData"}} />
<br>
<br>
For <Input @value={{this.startDate}} /> to <Input @value={{this.endDate}} />
<button {{on "click" go}}>Update</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.12.4",
"ember-template-compiler": "3.12.4",
"ember-testing": "3.12.4"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment