Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
luctst committed Oct 3, 2020
1 parent 6ed6104 commit 09ec616
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 125 deletions.
84 changes: 0 additions & 84 deletions lib/main.js
@@ -1,13 +1,9 @@
/**
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
* Create a new lazy HTMLElement everytime you scroll on the last element.
* @param {HTMLElement} container - The container where the HTML Element must be create.
* @param {Array} ops - An array of object this will be the element that Leo will create on scroll.
*/
module.exports = class Leo {
<<<<<<< HEAD
constructor(container, ops) {
if (typeof container !== "string") {
throw new Error("Container must be a string");
Expand Down Expand Up @@ -64,83 +60,3 @@ module.exports = class Leo {
);
}
};
=======
*
=======
*
>>>>>>> 441a6d9... Fix ci errors
=======
* Create a new lazy HTMLElement everytime you scroll on the last element.
* @param {HTMLElement} container - The container where the HTML Element must be create.
* @param {Array} ops - An array of object this will be the element that Leo will create on scroll.
>>>>>>> 51d8183... ADd container props and documentation
*/
class Leo {
=======
>>>>>>> 1511d91... Fix CI errors
constructor(container, ops) {
if (typeof container !== "string") {
throw new Error("Container must be a string");
}

if (!document.querySelector(container)) {
throw new Error("Container must be an HTML element");
}

if (!Array.isArray(ops)) {
throw new Error("Leo only accept array");
}

ops.forEach((element) => {
if (typeof element !== "object") {
throw new Error("Options only accepts objects");
}
});

this.data = [...ops];
this.container = container;
this.addSection();
}

addSection() {
let i = 0;

window.addEventListener(
"scroll",
function t() {
if (i > this.data.length) return removeEventListener("scroll", t);

if (
window.scrollY >=
document.querySelector(this.container).lastElementChild.offsetTop
) {
const e = document.createElement(this.data[i].htmlContainer);

if (this.data[i].class) {
this.data[i].class.forEach((el) => e.classList.add(el));
}

if (this.data[i].template) {
e.innerHTML = this.data[i].template;
}

document.querySelector(this.container).appendChild(e);

<<<<<<< HEAD
i++;
return;
}
}.bind(this));
}
}
>>>>>>> 0a32806... Leo class
=======
i += 1;
}

return true;
}.bind(this)
);
}
};
>>>>>>> 441a6d9... Fix ci errors
4 changes: 0 additions & 4 deletions package.json
Expand Up @@ -64,10 +64,6 @@
"eslint-plugin-prettier": "^3.1.4",
"eslint-watch": "^7.0.0",
"prettier": "^2.1.2",
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/polyfill": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"np": "^6.5.0"
}
}
38 changes: 1 addition & 37 deletions test/test.js
@@ -1,7 +1,3 @@
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 5e076af... Start writing tests
const test = require("ava");
const browserEnv = require("browser-env");
let Leo;
Expand All @@ -10,54 +6,22 @@ browserEnv(['window', 'document']);

test.before(function () {
Leo = require("../lib/main");
<<<<<<< HEAD
<<<<<<< HEAD

document.querySelector("body").appendChild(document.createElement("main"));
})

test('Options should be an array', function (t) {
const error = t.throws(() => new Leo("main", {}), {
=======
})
test('Options should be an array', function (t) {
const error = t.throws(() => new Leo({}), {
>>>>>>> 5e076af... Start writing tests
=======
document.querySelector("body").appendChild(document.createElement("main"));
})
test('Options should be an array', function (t) {
const error = t.throws(() => new Leo("main", {}), {
>>>>>>> 1511d91... Fix CI errors
instanceOf: Error,
});

t.is(error.message, 'Leo only accept array');
});

test('Options data should be objects', function (t) {
<<<<<<< HEAD
<<<<<<< HEAD
const e = t.throws(() => new Leo("main", [""]), {
=======
const e = t.throws(() => new Leo([""]), {
>>>>>>> 5e076af... Start writing tests
=======
const e = t.throws(() => new Leo("main", [""]), {
>>>>>>> 1511d91... Fix CI errors
instanceOf: Error
});

t.is(e.message, 'Options only accepts objects');
<<<<<<< HEAD
});
=======
const ava = require("ava");
ava.todo("Implement test");
>>>>>>> 448f9eb... Make test script passed
=======
});
>>>>>>> 5e076af... Start writing tests
});

0 comments on commit 09ec616

Please sign in to comment.