├── .editorconfig ├── .ember-cli ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .npmignore ├── .prettierrc ├── .template-lintrc.js ├── .travis.yml ├── .watchmanconfig ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── addon └── modifiers │ └── ref.js ├── app └── modifiers │ └── ref.js ├── config ├── ember-try.js ├── environment.js └── optional-features.json ├── ember-cli-build.js ├── index.js ├── jsconfig.json ├── package.json ├── testem.js ├── tests ├── dummy │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ ├── .gitkeep │ │ │ ├── glimmer-ref.hbs │ │ │ ├── glimmer-ref.js │ │ │ └── ref-sample │ │ │ │ ├── component.js │ │ │ │ └── template.hbs │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── index.html │ │ ├── models │ │ │ └── .gitkeep │ │ ├── resolver.js │ │ ├── router.js │ │ ├── routes │ │ │ └── .gitkeep │ │ ├── styles │ │ │ └── app.css │ │ └── templates │ │ │ ├── application.hbs │ │ │ └── components │ │ │ └── .gitkeep │ ├── config │ │ ├── ember-cli-update.json │ │ ├── environment.js │ │ ├── optional-features.json │ │ └── targets.js │ └── public │ │ └── robots.txt ├── helpers │ └── .gitkeep ├── index.html ├── integration │ ├── .gitkeep │ └── modifiers │ │ └── ref-test.js ├── test-helper.js └── unit │ └── .gitkeep ├── vendor └── .gitkeep └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.hbs] 16 | insert_final_newline = false 17 | 18 | [*.{diff,md}] 19 | trim_trailing_whitespace = false 20 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | 17 | # ember-try 18 | /.node_modules.ember-try/ 19 | /bower.json.ember-try 20 | /package.json.ember-try 21 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | ecmaVersion: 2018, 8 | sourceType: 'module', 9 | ecmaFeatures: { 10 | legacyDecorators: true 11 | } 12 | }, 13 | plugins: ['prettier', 'ember'], 14 | extends: [ 15 | 'plugin:prettier/recommended', 16 | 'eslint:recommended', 17 | 'plugin:ember/recommended' 18 | ], 19 | env: { 20 | browser: true 21 | }, 22 | rules: {}, 23 | overrides: [ 24 | // node files 25 | { 26 | files: [ 27 | '.eslintrc.js', 28 | '.template-lintrc.js', 29 | 'ember-cli-build.js', 30 | 'index.js', 31 | 'testem.js', 32 | 'blueprints/*/index.js', 33 | 'config/**/*.js', 34 | 'tests/dummy/config/**/*.js', 35 | 'server/**/*.js' 36 | ], 37 | excludedFiles: [ 38 | 'addon/**', 39 | 'addon-test-support/**', 40 | 'app/**', 41 | 'tests/dummy/app/**' 42 | ], 43 | parserOptions: { 44 | sourceType: 'script' 45 | }, 46 | env: { 47 | browser: false, 48 | node: true 49 | }, 50 | plugins: ['node'], 51 | extends: ['plugin:node/recommended'] 52 | } 53 | ] 54 | }; 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist/ 5 | /tmp/ 6 | 7 | # dependencies 8 | /bower_components/ 9 | /node_modules/ 10 | 11 | # misc 12 | /.env* 13 | /.sass-cache 14 | /connect.lock 15 | /coverage/ 16 | /libpeerconnection.log 17 | /npm-debug.log* 18 | /testem.log 19 | /yarn-error.log 20 | 21 | # ember-try 22 | /.node_modules.ember-try/ 23 | /bower.json.ember-try 24 | /package.json.ember-try 25 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist/ 3 | /tmp/ 4 | 5 | # dependencies 6 | /bower_components/ 7 | 8 | # misc 9 | /.bowerrc 10 | /.editorconfig 11 | /.ember-cli 12 | /.env* 13 | /.eslintignore 14 | /.eslintrc.js 15 | /.gitignore 16 | /.template-lintrc.js 17 | /.travis.yml 18 | /.watchmanconfig 19 | /bower.json 20 | /config/ember-try.js 21 | /CONTRIBUTING.md 22 | /ember-cli-build.js 23 | /testem.js 24 | /tests/ 25 | /yarn.lock 26 | .gitkeep 27 | 28 | # ember-try 29 | /.node_modules.ember-try/ 30 | /bower.json.ember-try 31 | /package.json.ember-try 32 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "overrides": [ 4 | { 5 | "files": "*.hbs", 6 | "options": { 7 | "singleQuote": false 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /.template-lintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'octane' 5 | }; 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | # we recommend testing addons with the same minimum supported node version as Ember CLI 5 | # so that your addon works for all apps 6 | - "10" 7 | 8 | dist: xenial 9 | 10 | addons: 11 | chrome: stable 12 | 13 | cache: 14 | yarn: true 15 | 16 | env: 17 | global: 18 | # See https://git.io/vdao3 for details. 19 | - JOBS=1 20 | 21 | branches: 22 | only: 23 | - master 24 | # npm version tags 25 | - /^v\d+\.\d+\.\d+/ 26 | - /^greenkeeper/.*$/ 27 | 28 | jobs: 29 | fast_finish: true 30 | allow_failures: 31 | - env: EMBER_TRY_SCENARIO=ember-canary 32 | 33 | include: 34 | # runs linting and tests with current locked deps 35 | 36 | - stage: 'Tests' 37 | name: 'Tests' 38 | install: 39 | - yarn install --non-interactive 40 | script: 41 | - yarn lint 42 | - yarn test:ember 43 | 44 | - name: 'Floating Dependencies' 45 | script: 46 | - yarn test:ember 47 | 48 | # we recommend new addons test the current and previous LTS 49 | # as well as latest stable release (bonus points to beta/canary) 50 | - env: EMBER_TRY_SCENARIO=ember-lts-3.12 51 | - env: EMBER_TRY_SCENARIO=ember-lts-3.16 52 | - env: EMBER_TRY_SCENARIO=ember-release 53 | - env: EMBER_TRY_SCENARIO=ember-beta 54 | - env: EMBER_TRY_SCENARIO=ember-canary 55 | - env: EMBER_TRY_SCENARIO=ember-default-with-jquery 56 | 57 | before_install: 58 | - curl -o- -L https://yarnpkg.com/install.sh | bash 59 | - export PATH=$HOME/.yarn/bin:$PATH 60 | 61 | install: 62 | - yarn install --no-lockfile --non-interactive 63 | 64 | script: 65 | - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO 66 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How To Contribute 2 | 3 | ## Installation 4 | 5 | * `git clone ` 6 | * `cd ember-ref-modifier` 7 | * `yarn install` 8 | 9 | ## Linting 10 | 11 | * `yarn lint:hbs` 12 | * `yarn lint:js` 13 | * `yarn lint:js --fix` 14 | 15 | ## Running tests 16 | 17 | * `ember test` – Runs the test suite on the current Ember version 18 | * `ember test --server` – Runs the test suite in "watch mode" 19 | * `ember try:each` – Runs the test suite against multiple Ember versions 20 | 21 | ## Running the dummy application 22 | 23 | * `ember serve` 24 | * Visit the dummy application at [http://localhost:4200](http://localhost:4200). 25 | 26 | For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). 27 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-ref-modifier 2 | 3 | [![Greenkeeper badge](https://badges.greenkeeper.io/lifeart/ember-ref-modifier.svg)](https://greenkeeper.io/) 4 | 5 | ------------ 6 | 7 | ## Check [ember-ref-bucket](https://github.com/lifeart/ember-ref-bucket) first! 8 | 9 | **`ember-ref-modifier`** likely will be **deprecated** after **`ember-ref-bucket`** major release 10 | 11 | ------------ 12 | 13 | An implementation of the `{{ref}}` element modifier. 14 | Heavily inspired by [ember-on-modifier](https://github.com/buschtoens/ember-on-modifier) and [`@ember/render-modifiers`](https://github.com/emberjs/ember-render-modifiers). 15 | 16 | ## Installation 17 | 18 | ``` 19 | ember install ember-ref-modifier 20 | ``` 21 | 22 | #### Compatibility 23 | 24 | - Ember.js v3.13 or above 25 | - ember-cli v2.13 or above 26 | 27 | ## Usage 28 | 29 | ```hbs 30 | 33 | 34 | {{this.button.dataset.name}} >> "foo" 35 | ``` 36 | 37 | -------------------------- 38 | 39 | ```hbs 40 | 43 | ``` 44 | 45 | ```js 46 | class Component { 47 | @action callback(node) { 48 | this.node = node; 49 | } 50 | } 51 | 52 | ``` 53 | 54 | ------------------------ 55 | 56 | ```hbs 57 |
58 | {{#-in-element this.divContainer}} 59 | Hello! 60 | {{/-in-element}} 61 | ``` 62 | ------------------------ 63 | 64 | 65 | ```hbs 66 | // hash helper must return an EmberObject! The default hash helper returns a pojo. 67 | {{#let (hash) as |ctx|}} 68 | 69 | 70 | {{/let}} 71 | ``` 72 | 73 | 74 | ------------------------ 75 | 76 | ------ 77 | 78 | ```hbs 79 | 82 | ``` 83 | 84 | ```ts 85 | import Component from '@ember/component'; 86 | 87 | export default class BritneySpearsComponent extends Component { 88 | button!: DOMNode 89 | } 90 | ``` 91 | 92 | 93 | This is essentially equivalent to: 94 | 95 | ```ts 96 | didInsertElement() { 97 | super.didInsertElement(); 98 | this.set('button', this.element.querySelector('button')); 99 | } 100 | ``` 101 | 102 | It will also re-register property, if any of the passed parameters change. 103 | -------------------------------------------------------------------------------- /addon/modifiers/ref.js: -------------------------------------------------------------------------------- 1 | import { set, get } from '@ember/object'; 2 | import { assert } from '@ember/debug'; 3 | import { setModifierManager, capabilities } from '@ember/modifier'; 4 | import { cancel, next } from '@ember/runloop'; 5 | function hasValidTarget(target) { 6 | return ( 7 | typeof target === 'object' && target !== null && !Array.isArray(target) 8 | ); 9 | } 10 | function hasValidProperty(prop) { 11 | return typeof prop === 'string'; 12 | } 13 | function getParams([target, propName]) { 14 | if (typeof target === 'function') { 15 | return { 16 | cb: target 17 | }; 18 | } 19 | assert( 20 | `String ${target} used as context for ref modifier. Should be {{ref context "${target}"}}. You passed {{ref "${target}" context}}`, 21 | typeof target !== 'string' 22 | ); 23 | return { target, propName }; 24 | } 25 | 26 | export default setModifierManager( 27 | () => ({ 28 | _runCache: new Set(), 29 | 30 | capabilities: capabilities ? capabilities('3.13') : undefined, 31 | createModifier() { 32 | return { 33 | element: undefined, 34 | propName: undefined, 35 | cb: undefined, 36 | target: undefined 37 | }; 38 | }, 39 | 40 | installModifier(state, element, { positional }) { 41 | const { propName, target, cb } = getParams(positional); 42 | if (cb) { 43 | state.cb = cb; 44 | this._runInContext(cb, element); 45 | return; 46 | } 47 | if (hasValidProperty(propName) && hasValidTarget(target)) { 48 | this._setInContext(target, propName, element); 49 | state.propName = propName; 50 | state.target = target; 51 | } 52 | state.element = element; 53 | }, 54 | 55 | updateModifier(state, { positional }) { 56 | const { propName, target, cb } = getParams(positional); 57 | if (cb) { 58 | state.cb = cb; 59 | this._runInContext(cb, state.element); 60 | return; 61 | } 62 | if (hasValidProperty(propName) && hasValidTarget(target)) { 63 | if (hasValidProperty(state.propName) && hasValidTarget(state.target)) { 64 | if (get(target, propName) !== get(state.target, state.propName)) { 65 | this._setInContext(state.target, state.propName, null); 66 | } 67 | } 68 | this._setInContext(target, propName, state.element); 69 | state.propName = propName; 70 | state.target = target; 71 | } 72 | }, 73 | _setInContext(target, propName, value) { 74 | const cancelToken = next(this, '_setValues', target, propName, value); 75 | this._runCache.add(cancelToken); 76 | }, 77 | _runInContext(cb, value) { 78 | const cancelToken = next(this, '_runCb', cb, value); 79 | this._runCache.add(cancelToken); 80 | }, 81 | _runCb(cb, value) { 82 | cb(value); 83 | }, 84 | _setValues(target, propName, value) { 85 | if (target.isDestroyed || target.isDestroying) { 86 | return; 87 | } 88 | set(target, propName, value); 89 | }, 90 | destroyModifier({ target, propName, cb }) { 91 | this._runCache.forEach(cancelToken => cancel(cancelToken)); 92 | 93 | if (cb) { 94 | return; 95 | } 96 | if (hasValidProperty(propName) && hasValidTarget(target)) { 97 | this._setInContext(target, propName, null); 98 | } 99 | } 100 | }), 101 | class RefModifier {} 102 | ); 103 | -------------------------------------------------------------------------------- /app/modifiers/ref.js: -------------------------------------------------------------------------------- 1 | export { default } from 'ember-ref-modifier/modifiers/ref'; 2 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getChannelURL = require('ember-source-channel-url'); 4 | 5 | module.exports = async function() { 6 | return { 7 | scenarios: [ 8 | { 9 | name: 'ember-lts-3.12', 10 | npm: { 11 | devDependencies: { 12 | 'ember-source': '~3.12.0' 13 | } 14 | } 15 | }, 16 | { 17 | name: 'ember-lts-3.16', 18 | npm: { 19 | devDependencies: { 20 | 'ember-source': '~3.16.0' 21 | } 22 | } 23 | }, 24 | { 25 | name: 'ember-release', 26 | npm: { 27 | devDependencies: { 28 | 'ember-source': await getChannelURL('release') 29 | } 30 | } 31 | }, 32 | { 33 | name: 'ember-beta', 34 | npm: { 35 | devDependencies: { 36 | 'ember-source': await getChannelURL('beta') 37 | } 38 | } 39 | }, 40 | { 41 | name: 'ember-canary', 42 | npm: { 43 | devDependencies: { 44 | 'ember-source': await getChannelURL('canary') 45 | } 46 | } 47 | }, 48 | // The default `.travis.yml` runs this scenario via `npm test`, 49 | // not via `ember try`. It's still included here so that running 50 | // `ember try:each` manually or from a customized CI config will run it 51 | // along with all the other scenarios. 52 | { 53 | name: 'ember-default', 54 | npm: { 55 | devDependencies: {} 56 | } 57 | }, 58 | { 59 | name: 'ember-default-with-jquery', 60 | env: { 61 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 62 | 'jquery-integration': true 63 | }) 64 | }, 65 | npm: { 66 | devDependencies: { 67 | '@ember/jquery': '^0.5.1' 68 | } 69 | } 70 | }, 71 | { 72 | name: 'ember-classic', 73 | env: { 74 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 75 | 'application-template-wrapper': true, 76 | 'default-async-observers': false, 77 | 'template-only-glimmer-components': false 78 | }) 79 | }, 80 | npm: { 81 | ember: { 82 | edition: 'classic' 83 | } 84 | } 85 | } 86 | ] 87 | }; 88 | }; 89 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(/* environment, appConfig */) { 4 | return {}; 5 | }; 6 | -------------------------------------------------------------------------------- /config/optional-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "application-template-wrapper": false, 3 | "default-async-observers": true, 4 | "jquery-integration": true 5 | "jquery-integration": false, 6 | "template-only-glimmer-components": true 7 | } -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 4 | 5 | module.exports = function(defaults) { 6 | let app = new EmberAddon(defaults, { 7 | // Add options here 8 | }); 9 | 10 | /* 11 | This build file specifies the options for the dummy test app of this 12 | addon, located in `/tests/dummy` 13 | This build file does *not* influence how the addon or the app using it 14 | behave. You most likely want to be modifying `./index.js` or app's build file 15 | */ 16 | 17 | return app.toTree(); 18 | }; 19 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | name: require('./package').name 5 | }; 6 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | {"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-ref-modifier", 3 | "version": "1.0.1", 4 | "description": "Ember DOM reference modifier", 5 | "keywords": [ 6 | "ember-addon", 7 | "ember-modifier", 8 | "ember-element-modifier", 9 | "ref-modifier", 10 | "ref" 11 | ], 12 | "repository": "lifeart/ember-ref-modifier", 13 | "license": "MIT", 14 | "author": "Aleksandr Kanunnikov ", 15 | "directories": { 16 | "doc": "doc", 17 | "test": "tests" 18 | }, 19 | "scripts": { 20 | "build": "ember build --environment=production", 21 | "lint": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*", 22 | "lint:hbs": "ember-template-lint .", 23 | "lint:js": "eslint .", 24 | "start": "ember serve", 25 | "test": "npm-run-all lint:* test:*", 26 | "test:ember": "ember test", 27 | "test:ember-compatibility": "ember try:each" 28 | }, 29 | "dependencies": { 30 | "ember-cli-babel": "^7.20.5" 31 | }, 32 | "devDependencies": { 33 | "@ember/optional-features": "^1.3.0", 34 | "@glimmer/component": "^1.0.0", 35 | "@glimmer/tracking": "^1.0.0", 36 | "babel-eslint": "^10.1.0", 37 | "broccoli-asset-rev": "^3.0.0", 38 | "ember-cli": "~3.19.0", 39 | "ember-cli-dependency-checker": "^3.0.0", 40 | "ember-cli-htmlbars": "^5.1.2", 41 | "ember-cli-inject-live-reload": "^2.0.2", 42 | "ember-cli-sri": "^2.1.1", 43 | "ember-cli-uglify": "^2.1.0", 44 | "ember-disable-prototype-extensions": "^1.1.3", 45 | "ember-export-application-global": "^2.0.0", 46 | "ember-load-initializers": "^2.0.0", 47 | "ember-maybe-import-regenerator": "^0.1.6", 48 | "ember-modifier-manager-polyfill": "^1.0.1", 49 | "ember-qunit": "^4.2.0", 50 | "ember-resolver": "^8.0.0", 51 | "ember-source": "~3.19.0", 52 | "ember-source-channel-url": "^1.1.0", 53 | "ember-template-lint": "^2.8.0", 54 | "ember-try": "^1.0.0", 55 | "eslint": "^7.1.0", 56 | "eslint-config-prettier": "^6.1.0", 57 | "eslint-plugin-ember": "^8.6.0", 58 | "eslint-plugin-node": "^11.1.0", 59 | "eslint-plugin-prettier": "^3.0.1", 60 | "loader.js": "^4.7.0", 61 | "npm-run-all": "^4.1.5", 62 | "prettier": "^1.16.1", 63 | "qunit-dom": "^1.2.0" 64 | }, 65 | "ember": { 66 | "edition": "octane" 67 | }, 68 | "engines": { 69 | "node": "10.* || >= 12" 70 | }, 71 | "ember-addon": { 72 | "configPath": "tests/dummy/config" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | test_page: 'tests/index.html?hidepassed', 5 | disable_watching: true, 6 | launch_in_ci: ['Chrome'], 7 | launch_in_dev: ['Chrome'], 8 | browser_start_timeout: 120, 9 | browser_args: { 10 | Chrome: { 11 | ci: [ 12 | // --no-sandbox is needed when running Chrome inside a container 13 | process.env.CI ? '--no-sandbox' : null, 14 | '--headless', 15 | '--disable-gpu', 16 | '--disable-dev-shm-usage', 17 | '--disable-software-rasterizer', 18 | '--mute-audio', 19 | '--remote-debugging-port=0', 20 | '--window-size=1440,900' 21 | ].filter(Boolean) 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Application from '@ember/application'; 2 | import Resolver from './resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from './config/environment'; 5 | 6 | const App = Application.extend({ 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix, 9 | Resolver 10 | }); 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/components/glimmer-ref.hbs: -------------------------------------------------------------------------------- 1 |
2 | Hello, {{this.size}} 3 |
-------------------------------------------------------------------------------- /tests/dummy/app/components/glimmer-ref.js: -------------------------------------------------------------------------------- 1 | import Component from '@glimmer/component'; 2 | import { tracked } from '@glimmer/tracking'; 3 | 4 | export default class GlimmerRefComponent extends Component { 5 | @tracked 6 | node = null; 7 | get size() { 8 | return this.node && this.node.clientWidth; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/dummy/app/components/ref-sample/component.js: -------------------------------------------------------------------------------- 1 | import Component from '@ember/component'; 2 | import layout from './template'; 3 | 4 | export default Component.extend({ 5 | layout 6 | }); 7 | -------------------------------------------------------------------------------- /tests/dummy/app/components/ref-sample/template.hbs: -------------------------------------------------------------------------------- 1 |
2 | {{#-in-element this.divContainer}} 3 | Hello! 4 | {{/-in-element}} 5 | -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember-resolver'; 2 | 3 | export default Resolver; 4 | -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import EmberRouter from '@ember/routing/router'; 2 | import config from './config/environment'; 3 | 4 | const Router = EmberRouter.extend({ 5 | location: config.locationType, 6 | rootURL: config.rootURL 7 | }); 8 | 9 | Router.map(function() {}); 10 | 11 | export default Router; 12 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/dummy/app/styles/app.css -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 |

Welcome to Ember

2 | 3 | {{outlet}} 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/dummy/app/templates/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/config/ember-cli-update.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": "1.0.0", 3 | "packages": [ 4 | { 5 | "name": "ember-cli", 6 | "version": "3.19.0", 7 | "blueprints": [ 8 | { 9 | "name": "addon", 10 | "outputRepo": "https://github.com/ember-cli/ember-addon-output", 11 | "codemodsSource": "ember-addon-codemods-manifest@1", 12 | "isBaseBlueprint": true, 13 | "options": [ 14 | "--yarn", 15 | "--no-welcome" 16 | ] 17 | } 18 | ] 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(environment) { 4 | let ENV = { 5 | modulePrefix: 'dummy', 6 | environment, 7 | rootURL: '/', 8 | locationType: 'auto', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. 'with-controller': true 13 | }, 14 | EXTEND_PROTOTYPES: { 15 | // Prevent Ember Data from overriding Date.parse. 16 | Date: false 17 | } 18 | }, 19 | 20 | APP: { 21 | // Here you can pass flags/options to your application instance 22 | // when it is created 23 | } 24 | }; 25 | 26 | if (environment === 'development') { 27 | // ENV.APP.LOG_RESOLVER = true; 28 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 29 | // ENV.APP.LOG_TRANSITIONS = true; 30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 31 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 32 | } 33 | 34 | if (environment === 'test') { 35 | // Testem prefers this... 36 | ENV.locationType = 'none'; 37 | 38 | // keep test console output quieter 39 | ENV.APP.LOG_ACTIVE_GENERATION = false; 40 | ENV.APP.LOG_VIEW_LOOKUPS = false; 41 | 42 | ENV.APP.rootElement = '#ember-testing'; 43 | ENV.APP.autoboot = false; 44 | } 45 | 46 | if (environment === 'production') { 47 | // here you can enable a production-specific feature 48 | } 49 | 50 | return ENV; 51 | }; 52 | -------------------------------------------------------------------------------- /tests/dummy/config/optional-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "application-template-wrapper": false, 3 | "jquery-integration": false, 4 | "template-only-glimmer-components": true 5 | } 6 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browsers = [ 4 | 'last 1 Chrome versions', 5 | 'last 1 Firefox versions', 6 | 'last 1 Safari versions' 7 | ]; 8 | 9 | const isCI = !!process.env.CI; 10 | const isProduction = process.env.EMBER_ENV === 'production'; 11 | 12 | if (isCI || isProduction) { 13 | browsers.push('ie 11'); 14 | } 15 | 16 | module.exports = { 17 | browsers 18 | }; 19 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | {{content-for "test-head"}} 12 | 13 | 14 | 15 | 16 | 17 | {{content-for "head-footer"}} 18 | {{content-for "test-head-footer"}} 19 | 20 | 21 | {{content-for "body"}} 22 | {{content-for "test-body"}} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {{content-for "body-footer"}} 31 | {{content-for "test-body-footer"}} 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/integration/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/integration/.gitkeep -------------------------------------------------------------------------------- /tests/integration/modifiers/ref-test.js: -------------------------------------------------------------------------------- 1 | import { module, test } from 'qunit'; 2 | import { setupRenderingTest } from 'ember-qunit'; 3 | import { render } from '@ember/test-helpers'; 4 | import hbs from 'htmlbars-inline-precompile'; 5 | 6 | module('Integration | Modifier | ref', function(hooks) { 7 | setupRenderingTest(hooks); 8 | 9 | test('it basically works', async function(assert) { 10 | assert.expect(1); 11 | 12 | await render( 13 | hbs`` 14 | ); 15 | assert.equal(this.btn.dataset.foo, 'some-thing'); 16 | }); 17 | 18 | test('it is re-registered, when attrs changed', async function(assert) { 19 | assert.expect(3); 20 | 21 | await render( 22 | hbs`` 23 | ); 24 | 25 | assert.equal(this.btn.dataset.foo, 'some-thing'); 26 | 27 | await render( 28 | hbs`` 29 | ); 30 | 31 | assert.equal(this.btn, null); 32 | assert.equal(this.btns.dataset.foo, 'some-thing'); 33 | }); 34 | 35 | test('it does nothing if ref key or target `null` or `undefined`', async function(assert) { 36 | assert.expect(0); 37 | await render(hbs` 38 | 39 | 40 | 41 | 42 | 43 | `); 44 | }); 45 | 46 | test('it does not crash when updating to or from `null` / `undefined`', async function(assert) { 47 | assert.expect(2); 48 | 49 | this.set('ctx', null); 50 | await render(hbs``); 51 | assert.equal(this.btn, undefined); 52 | this.set('ctx', this); 53 | await new Promise(resolve => setTimeout(resolve)); 54 | assert.equal(this.btn.tagName, 'BUTTON'); 55 | }); 56 | 57 | test('it support callbacks', async function(assert) { 58 | assert.expect(1); 59 | 60 | let node = null; 61 | this.set('ctx', function(value) { 62 | node = value; 63 | }); 64 | await render(hbs``); 65 | assert.equal(node.tagName, 'BUTTON'); 66 | }); 67 | }); 68 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from '../app'; 2 | import config from '../config/environment'; 3 | import { setApplication } from '@ember/test-helpers'; 4 | import { start } from 'ember-qunit'; 5 | 6 | setApplication(Application.create(config.APP)); 7 | 8 | start(); 9 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/tests/unit/.gitkeep -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifeart/ember-ref-modifier/a918db60ec96101094f01a7a2a53852e7845b735/vendor/.gitkeep --------------------------------------------------------------------------------