Last active
May 4, 2020 16:09
-
-
Save nightire/771c7170f2a1141dfed1a0bb43ec8be3 to your computer and use it in GitHub Desktop.
Compare filtering items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
} else { | |
return this.options; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@glimmer/component'; | |
import { tracked } from '@glimmer/tracking'; | |
export default class extends Component { | |
@tracked query = ''; | |
get options() { | |
if (this.query) { | |
return this.args.options.filter((option) => { | |
return option.value.toLowerCase().lastIndexOf(this.query, 0) === 0; | |
}); | |
} else { | |
return this.args.options; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import randomString from 'twiddle/utils/random-string'; | |
function generateOptions(amount) { | |
return Array.from(Array(amount)).map(() => ({ value: randomString() })); | |
} | |
export default class ApplicationController extends Controller { | |
appName = randomString(); | |
options = generateOptions(5000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.0", | |
"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.3.1/jquery.js", | |
"ember": "3.17.0", | |
"ember-template-compiler": "3.17.0", | |
"ember-testing": "3.17.0" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
export default function randomString(amount = 8) { | |
return Array.from(Array(amount)).reduce((finale) => { | |
return `${finale}${CHARS.charAt(Math.floor(Math.random() * CHARS.length))}`; | |
}, ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment