Skip to content

Instantly share code, notes, and snippets.

View nightire's full-sized avatar
Looking for new opportunities

余凡 nightire

Looking for new opportunities
View GitHub Profile
@nightire
nightire / components.change-password\.js
Last active May 22, 2020 04:41
Octane way of changing password
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
const MESSAGES = {
staled: 'The old password and new password are the same. The password was not changed.',
invalid: 'The new password and confirm password must be the same value. The password was not changed.'
};
export default class extends Component {
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
export default class extends Component {
@tracked tags = ['programming', 'rails'];
@tracked tag = '';
@action addTag(event) {
@nightire
nightire / components.classic-search\.js
Last active May 4, 2020 16:09
Compare filtering items
import Component from '@ember/component';
import { computed } from '@ember/object';
export default class extends Component {
query = '';
@computed('query') get _options() {
if (this.query) {
return this.options.filter((option) => {
return option.value.toLowerCase().lastIndexOf(this.query, 0) === 0;
import Ember from 'ember';
const { Component, computed } = Ember;
const BlogPostCardComponent = Component.extend({
classNames: ['blog-post-card', 'card'],
classNameBindings: ['disabled::clickable'],
click() {
if (!this.get('disabled')) {
this.get('viewPost')(this.get('post'));
@nightire
nightire / controllers.application\.js
Last active April 20, 2020 07:41
passing @query into component
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
queryParams = [
'page'
];
@tracked page;
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class ChangePasswordForm extends Component {
@tracked oldPassword;
@tracked newPassword;
@tracked confirmPassword;
import Component from '@glimmer/component';
export default class extends Component {
get shouldLimit() {
return this.args.items.length > this.args.showMax;
}
get items() {
if (this.shouldLimit) {
const [...items] = this.args.items;
@nightire
nightire / controllers.application\.js
Created March 4, 2020 03:06
example to use each-in
import Controller from '@ember/controller';
class ApplicationController extends Controller {
abvalues = [
{a:{title:"First A"},b:{title:"First B"}},
{a:{title:"Second A"},b:{title:"Second B"}},
]
}
export default ApplicationController;
@nightire
nightire / application.route.js
Last active October 10, 2019 09:39 — forked from houfeng0923/application.route.js
Data Binding
import Ember from 'ember';
export default Ember.Route.extend({
activate() {
document.body.classList.add('standard');
}
});
@nightire
nightire / controllers.application.js
Last active January 4, 2019 08:05
Change state by route link
import Controller from '@ember/controller';
import { inject } from '@ember/service';
import { set } from '@ember/object';
export default Controller.extend({
state: inject(),
router: inject(),