Skip to content

Commit 24dd2da

Browse files
committed
refactoring to ts
1 parent bee56af commit 24dd2da

23 files changed

+201
-309
lines changed

.eslintrc

Lines changed: 1 addition & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -14,205 +14,5 @@
1414
}
1515
},
1616
"parser": "babel-eslint",
17-
"plugins": ["babel", "react", "jest"],
18-
"rules": {
19-
/* Possible Errors */
20-
"comma-dangle": [1, "always-multiline"],
21-
"no-cond-assign": [1, "except-parens"],
22-
"no-console": 0,
23-
"no-constant-condition": 1,
24-
"no-control-regex": 1,
25-
"no-debugger": 1,
26-
"no-dupe-args": 1,
27-
"no-dupe-keys": 1,
28-
"no-duplicate-case": 0,
29-
"no-empty-character-class": 1,
30-
"no-empty": 0,
31-
"no-ex-assign": 1,
32-
"no-extra-boolean-cast": 1,
33-
"no-extra-parens": 0,
34-
"no-extra-semi": 1,
35-
"no-func-assign": 1,
36-
"no-inner-declarations": [1, "functions"],
37-
"no-invalid-regexp": 1,
38-
"no-irregular-whitespace": 1,
39-
"no-negated-in-lhs": 1,
40-
"no-obj-calls": 1,
41-
"no-regex-spaces": 1,
42-
"no-reserved-keys": 0,
43-
"no-sparse-arrays": 1,
44-
"no-unexpected-multiline": 1,
45-
"no-unreachable": 1,
46-
"use-isnan": 1,
47-
"valid-jsdoc": 0,
48-
"valid-typeof": 1,
49-
50-
/* Best Practices */
51-
"accessor-pairs": 0,
52-
"block-scoped-var": 0, // see Babel section
53-
"complexity": 0,
54-
"consistent-return": 1,
55-
"curly": 0,
56-
"default-case": 0,
57-
"dot-notation": [1, { "allowKeywords": true, "allowPattern": "" }],
58-
"dot-location": [1, "property"],
59-
"eqeqeq": 1,
60-
"guard-for-in": 0,
61-
"no-alert": 1,
62-
"no-caller": 1,
63-
"no-div-regex": 1,
64-
"no-else-return": 1,
65-
"no-eq-null": 0,
66-
"no-eval": 1,
67-
"no-extend-native": 0,
68-
"no-extra-bind": 1,
69-
"no-fallthrough": 0,
70-
"no-floating-decimal": 1,
71-
"no-implied-eval": 1,
72-
"no-iterator": 1,
73-
"no-labels": 1,
74-
"no-lone-blocks": 1,
75-
"no-loop-func": 1,
76-
"no-multi-spaces": 0,
77-
"no-multi-str": 1,
78-
"no-native-reassign": 1,
79-
"no-new-func": 1,
80-
"no-new-wrappers": 1,
81-
"no-new": 1,
82-
"no-octal-escape": 1,
83-
"no-octal": 1,
84-
"no-param-reassign": 0,
85-
"no-process-env": 0,
86-
"no-proto": 0,
87-
"no-redeclare": 1,
88-
"no-return-assign": 1,
89-
"no-script-url": 1,
90-
"no-self-compare": 1,
91-
"no-sequences": 1,
92-
"no-throw-literal": 1,
93-
"no-unused-expressions": 0,
94-
"no-void": 0,
95-
"no-warning-comments": 0,
96-
"no-with": 1,
97-
"radix": 1,
98-
"vars-on-top": 1,
99-
"wrap-iife": [1, "inside"],
100-
"yoda": [1, "never"],
101-
102-
/* Strict Mode */
103-
"strict": [1, "never"],
104-
105-
/* Variables */
106-
"no-catch-shadow": 0,
107-
"no-delete-var": 1,
108-
"no-label-var": 1,
109-
"no-shadow-restricted-names": 1,
110-
"no-shadow": 1,
111-
"no-undef-init": 1,
112-
"no-undef": 2,
113-
"no-undefined": 0,
114-
"no-unused-vars": 2,
115-
"no-use-before-define": 0,
116-
117-
/* Node.js */
118-
"handle-callback-err": 1,
119-
"no-mixed-requires": 1,
120-
"no-new-require": 1,
121-
"no-path-concat": 1,
122-
"no-process-exit": 1,
123-
"no-restricted-modules": [1, ""], // add any unwanted Node.js core modules
124-
"no-sync": 1,
125-
126-
/* Stylistic Issues */
127-
"array-bracket-spacing": [1, "never"],
128-
"brace-style": [2, "1tbs"],
129-
"camelcase": [1, { "properties": "always" }],
130-
"comma-spacing": [1, { "before": false, "after": true }],
131-
"comma-style": [1, "last"],
132-
"computed-property-spacing": 0,
133-
"consistent-this": 0,
134-
"eol-last": 1,
135-
"func-names": 0,
136-
"func-style": 0,
137-
"indent": 0,
138-
"key-spacing": [1, { "beforeColon": false, "afterColon": true }],
139-
"linebreak-style": 0,
140-
"max-nested-callbacks": [0, 3],
141-
"new-cap": 0, // see Babel section
142-
"new-parens": 1,
143-
"newline-after-var": 0,
144-
"no-array-constructor": 1,
145-
"no-continue": 1,
146-
"no-inline-comments": 0,
147-
"no-lonely-if": 1,
148-
"no-mixed-spaces-and-tabs": 1,
149-
"no-multiple-empty-lines": [1, { "max": 1 }],
150-
"no-nested-ternary": 0,
151-
"no-new-object": 1,
152-
"no-spaced-func": 1,
153-
"no-ternary": 0,
154-
"no-trailing-spaces": 1,
155-
"no-underscore-dangle": 0,
156-
"no-unneeded-ternary": 1,
157-
"object-curly-spacing": 0, // see Babel section
158-
"one-var": [1, "never"],
159-
"operator-assignment": [1, "never"],
160-
"padded-blocks": [0, "never"],
161-
"quote-props": [0, "as-needed"],
162-
"quotes": 0,
163-
"semi-spacing": [1, { "before": false, "after": true }],
164-
"semi": [1, "always"],
165-
"sort-vars": 0,
166-
"space-after-keywords": 0,
167-
"space-before-blocks": [1, "always"],
168-
"space-before-function-paren": [1, "never"],
169-
"space-in-parens": [1, "never"],
170-
"space-infix-ops": 1,
171-
"space-unary-ops": 0,
172-
"spaced-comment": [1, "always"],
173-
"wrap-regex": 1,
174-
175-
/* ECMAScript 6 */
176-
"constructor-super": 1,
177-
"generator-star-spacing": 1,
178-
"no-this-before-super": 1,
179-
"no-var": 1,
180-
"object-shorthand": 1,
181-
"prefer-const": 1,
182-
183-
/* Legacy */
184-
"max-depth": [0, 3],
185-
"max-len": [0, 121, 2],
186-
"max-params": 0,
187-
"max-statements": 0,
188-
"no-bitwise": 1,
189-
"no-plusplus": 0,
190-
191-
/* Babel */
192-
"babel/new-cap": 1,
193-
"babel/object-curly-spacing": [1, "always"],
194-
195-
/* React */
196-
"jsx-quotes": [1, "prefer-double"],
197-
"react/display-name": 1,
198-
"react/jsx-boolean-value": 1,
199-
"react/jsx-indent": [1, 4],
200-
"react/jsx-indent-props": [1, 4],
201-
"react/jsx-no-duplicate-props": 1,
202-
"react/jsx-no-undef": 1,
203-
"react/jsx-sort-props": 0,
204-
"react/jsx-uses-react": 1,
205-
"react/jsx-uses-vars": 1,
206-
"react/no-danger": 1,
207-
"react/no-did-mount-set-state": 1,
208-
"react/no-did-update-set-state": 1,
209-
"react/no-multi-comp": 0,
210-
"react/no-unknown-property": 1,
211-
"react/prop-types": 1,
212-
"react/react-in-jsx-scope": 1,
213-
"react/self-closing-comp": 1,
214-
"react/sort-comp": 1,
215-
"react/sort-prop-types": 1,
216-
"react/wrap-multilines": 0
217-
}
17+
"plugins": ["babel", "react", "jest"]
21818
}

src/classes/Bounds.js renamed to src/classes/Bounds.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
class Bounds {
2+
totalDistY: number;
3+
totalDistX: number;
4+
top: number;
5+
bottom: number;
6+
left: number;
7+
right: number;
8+
29
constructor(rect, offsets, view) {
310
const { y0, y1, x1, x0 } = offsets;
411

src/classes/Element.js renamed to src/classes/Element.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,24 @@ import {
88
import { VERTICAL } from '../constants';
99
import Bounds from './Bounds';
1010
import Rect from './Rect';
11+
import { ParallaxStartEndOffsets } from '../types';
1112

1213
export class Element {
14+
elInner: HTMLElement;
15+
elOuter: HTMLElement;
16+
// TODO
17+
props: any;
18+
scrollAxis: 'vertical' | 'horizontal';
19+
id: number;
20+
offsets: ParallaxStartEndOffsets;
21+
isInView: boolean;
22+
percent: number;
23+
24+
updatePosition: (view: any, scroll: any) => void;
25+
26+
rect: Rect;
27+
bounds: Bounds;
28+
1329
constructor(options) {
1430
this.elInner = options.elInner;
1531
this.elOuter = options.elOuter;
File renamed without changes.

src/classes/Rect.js renamed to src/classes/Rect.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
import { View } from './View';
2+
import { Scroll } from './Scroll';
3+
14
class Rect {
2-
constructor(el, view, scroll) {
5+
height: number;
6+
width: number;
7+
left: number;
8+
right: number;
9+
top: number;
10+
bottom: number;
11+
originTotalDistY: number;
12+
originTotalDistX: number;
13+
14+
constructor(el: HTMLElement, view: View, scroll: Scroll) {
315
let rect = el.getBoundingClientRect();
416

517
// rect is based on viewport -- must adjust for relative scroll container
618
if (view.scrollContainer) {
719
const scrollRect = view.scrollContainer.getBoundingClientRect();
820
rect = {
21+
...rect,
922
top: rect.top - scrollRect.top,
1023
right: rect.right - scrollRect.left,
1124
bottom: rect.bottom - scrollRect.top,

src/classes/Scroll.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/classes/Scroll.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export class Scroll {
2+
x: number;
3+
y: number;
4+
5+
constructor(x: number, y: number) {
6+
this.setScroll(x, y);
7+
}
8+
9+
setScroll(x: number, y: number) {
10+
this.x = x;
11+
this.y = y;
12+
return this;
13+
}
14+
}

src/classes/View.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/classes/View.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export class View {
2+
scrollContainer: HTMLElement;
3+
width: number;
4+
height: number;
5+
6+
constructor({
7+
width,
8+
height,
9+
scrollContainer,
10+
}: {
11+
width: number;
12+
height: number;
13+
scrollContainer: HTMLElement;
14+
}) {
15+
this.scrollContainer = scrollContainer;
16+
this.setSize(width, height);
17+
}
18+
19+
setSize(width: number, height: number) {
20+
this.width = width;
21+
this.height = height;
22+
return this;
23+
}
24+
}

0 commit comments

Comments
 (0)