Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ember-in-viewport to V2 addon #323

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ jobs:
- name: Install Node
uses: actions/setup-node@v2
with:
node-version: 12.x
node-version: 14.x
cache: npm
- name: Install Dependencies
run: npm ci
- name: Lint
run: npm run lint
run: pnpm run lint
- name: Run Tests
run: npm run test:ember
run: pnpm run test:ember
working-directory: test-app

floating:
name: "Floating Dependencies"
Expand All @@ -34,12 +35,13 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12.x
node-version: 14.x
cache: npm
- name: Install Dependencies
run: npm install --no-shrinkwrap
run: pnpm install --no-shrinkwrap
- name: Run Tests
run: npm run test:ember
run: pnpm run test:ember
working-directory: test-app

try-scenarios:
name: ${{ matrix.try-scenario }}
Expand Down Expand Up @@ -70,9 +72,10 @@ jobs:
- name: Install Node
uses: actions/setup-node@v2
with:
node-version: 12.x
node-version: 14.x
cache: npm
- name: Install Dependencies
run: npm ci
- name: Run Tests
run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }}
working-directory: test-app
30 changes: 5 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# you definitely want this:
node_modules

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
# and you can put in anything else that tends to accumulate in your environment:
yarn-error.log
.DS_Store
File renamed without changes.
58 changes: 58 additions & 0 deletions addon/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true,
},
rules: {
'getter-return': 0,
'ember/no-classic-classes': 0,
'ember/no-classic-components': 0,
'ember/require-tagless-components': 0,
},
overrides: [
// node files
{
files: [
'./.eslintrc.js',
'./.prettierrc.js',
'./.template-lintrc.js',
'./ember-cli-build.js',
'./addon-main.js',
'./testem.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./tests/dummy/config/**/*.js',
],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
{
// Test files:
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
],
};
26 changes: 26 additions & 0 deletions addon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions addon/addon-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { addonV1Shim } = require('@embroider/addon-shim');
module.exports = addonV1Shim(__dirname);
6 changes: 6 additions & 0 deletions addon/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-class-properties"
]
}
File renamed without changes.
80 changes: 80 additions & 0 deletions addon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "ember-in-viewport",
"version": "4.1.0",
"description": "Detect if an Ember View or Component is in the viewport @ 60FPS",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "rollup --config",
"lint": "eslint .",
"prepublishOnly": "rollup --config",
"start": "rollup --config --watch"
},
"repository": "https://github.com/dockyard/ember-in-viewport",
"engines": {
"node": "12.* || 14.* || >= 16"
},
"author": "Scott Newcomer",
"license": "MIT",
"dependencies": {
"@embroider/addon-shim": "^1.8.5",
"ember-destroyable-polyfill": "^2.0.3",
"ember-modifier": "^2.1.2 || ^3.0.0 || ^4.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.5.7",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-qunit": "^6.2.0",
"fast-deep-equal": "^2.0.1",
"intersection-observer-admin": "~0.3.2",
"prettier": "^2.4.1",
"raf-pool": "~0.1.4"
},
"keywords": [
"ember-addon",
"ember",
"viewport",
"intersection observer",
"lazy load",
"scrollspy"
],
"ember": {
"edition": "octane"
},
"volta": {
"node": "14.18.1"
},
"devDependencies": {
"@babel/core": "^7.21.8",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.21.0",
"@embroider/addon-dev": "^3.1.0",
"@rollup/plugin-babel": "^6.0.3",
"babel-eslint": "^10.1.0",
"npm-run-all": "^4.1.5",
"rollup": "^3.23.0"
},
"exports": {
".": "./dist/index.js",
"./*": "./dist/*",
"./test-support": "./dist/test-support/index.js",
"./addon-main.js": "./addon-main.js"
},
"files": [
"addon-main.js",
"dist"
],
"ember-addon": {
"main": "addon-main.js",
"type": "addon",
"version": 2,
"app-js": {
"./initializers/viewport-config.js": "./dist/_app_/initializers/viewport-config.js",
"./modifiers/in-viewport.js": "./dist/_app_/modifiers/in-viewport.js",
"./services/in-viewport.js": "./dist/_app_/services/in-viewport.js"
}
}
}
58 changes: 58 additions & 0 deletions addon/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import babel from '@rollup/plugin-babel';
import { Addon } from '@embroider/addon-dev/rollup';

const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
});

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
// You can augment this if you need to.
output: addon.output(),

plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints([
'initializers/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
'index.js'
]),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports([
'initializers/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
]),

// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.
//
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
babelHelpers: 'bundled',
}),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
// package names.
addon.dependencies(),

// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
// addon.keepAssets(['**/*.css']),

// Remove leftover build artifacts when starting a new build.
addon.clean(),
],
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RafPool from 'raf-pool';
import isInViewport from 'ember-in-viewport/utils/is-in-viewport';
import isInViewport from '../utils/is-in-viewport';

/**
* ensure use on requestAnimationFrame, no matter how many components
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import canUseDOM from 'ember-in-viewport/utils/can-use-dom';
import canUseDOM from '../utils/can-use-dom';

const defaultConfig = {
viewportDidScroll: true,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { set, setProperties } from '@ember/object';
import { getOwner } from '@ember/application';
import { warn } from '@ember/debug';
import { schedule } from '@ember/runloop';
import isInViewport from 'ember-in-viewport/utils/is-in-viewport';
import canUseRAF from 'ember-in-viewport/utils/can-use-raf';
import canUseIntersectionObserver from 'ember-in-viewport/utils/can-use-intersection-observer';
import ObserverAdmin from 'ember-in-viewport/-private/observer-admin';
import RAFAdmin, { startRAF } from 'ember-in-viewport/-private/raf-admin';
import isInViewport from '../utils/is-in-viewport';
import canUseRAF from '../utils/can-use-raf';
import canUseIntersectionObserver from '../utils/can-use-intersection-observer';
import ObserverAdmin from '../-private/observer-admin';
import RAFAdmin, { startRAF } from '../-private/raf-admin';

const noop = () => {};

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Adapted from WC3's intersection polyfill
// https://github.com/w3c/IntersectionObserver/blob/master/polyfill/intersection-observer.js

import canUseDOM from 'ember-in-viewport/utils/can-use-dom';
import canUseDOM from './can-use-dom';

function checkIntersectionObserver(window) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// MIT license

import canUseDOM from 'ember-in-viewport/utils/can-use-dom';
import canUseDOM from './can-use-dom';

function checkRAF(window, rAF, cAF) {
let x;
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions app/initializers/viewport-config.js

This file was deleted.

1 change: 0 additions & 1 deletion app/modifiers/in-viewport.js

This file was deleted.

1 change: 0 additions & 1 deletion app/services/in-viewport.js

This file was deleted.

Loading