Skip to content

Commit

Permalink
Merge pull request #190 from foretagsplatsen/dependabot/npm_and_yarn/…
Browse files Browse the repository at this point in the history
…foretagsplatsen/eslint-plugin-13.0.1

15549487: Bump @foretagsplatsen/eslint-plugin from 12.0.0 to 13.0.1
  • Loading branch information
DamienCassou authored Dec 2, 2024
2 parents e3149de + 628ebd9 commit 27e1739
Show file tree
Hide file tree
Showing 6 changed files with 1,514 additions and 171 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test:open": "vitest --ui"
},
"devDependencies": {
"@foretagsplatsen/eslint-plugin": "^12.0.0",
"@foretagsplatsen/eslint-plugin": "^13.0.1",
"@vitest/coverage-v8": "^2.0.2",
"@vitest/ui": "^2.0.2",
"eslint": "^9.13.0",
Expand Down
12 changes: 6 additions & 6 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
export default function event(spec, my) {
my ||= {};

let bindings = [];
const bindings = [];

// #### Public API

let that = {};
const that = {};

/**
* Binds callback to event. The callback will be invoked
Expand All @@ -39,9 +39,9 @@ export default function event(spec, my) {
function eventBinding(spec) {
spec ||= {};
// eslint-disable-next-line no-shadow -- we should fix that later
let that = {};
const that = {};

let callback = spec.callback;
const callback = spec.callback;
// eslint-disable-next-line no-shadow -- we should fix that later
let event = spec.event;

Expand Down Expand Up @@ -104,7 +104,7 @@ export default function event(spec, my) {
* @returns {eventBinding}
*/
that.registerOnce = function (callback) {
let onceBinding = eventBinding({
const onceBinding = eventBinding({
callback: function () {
my.remove(onceBinding);
callback.apply(that, arguments);
Expand All @@ -130,7 +130,7 @@ export default function event(spec, my) {
* @param arguments {Object|Object[]} Arguments passed to callback of each binding
*/
that.trigger = function () {
let params = Array.prototype.slice.call(arguments);
const params = Array.prototype.slice.call(arguments);

bindings.forEach((binding) => {
binding.execute(params);
Expand Down
6 changes: 3 additions & 3 deletions src/eventCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import event from "./event.js";
* Keeps a list of events.
*/
export default function eventCategory() {
let that = {};
const that = {};

// Map of events with name as key
let namedEvents = {};
Expand Down Expand Up @@ -69,9 +69,9 @@ export default function eventCategory() {
* @param arguments Any arguments to trigger is sent as arguments to callback.
*/
that.trigger = function (name) {
let params = Array.prototype.slice.call(arguments, 1);
const params = Array.prototype.slice.call(arguments, 1);
// eslint-disable-next-line no-shadow -- we should fix that later
let event = ensureEventHolderFor(name);
const event = ensureEventHolderFor(name);
event.trigger.apply(that, params);
};

Expand Down
8 changes: 5 additions & 3 deletions src/eventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import eventCategory from "./eventCategory.js";
* Singleton object that keeps a list of named event categories.
*/
const eventManager = (function () {
let that = {};
const that = {};

// Map of event categories with (category) name as key
let categories = {};
const categories = {};

/**
* Register a new event category with "name".
Expand All @@ -16,7 +16,9 @@ const eventManager = (function () {
*/
that.register = function (name) {
if (categories[name]) {
throw `A event category is already registered for ${name}`;
throw new Error(
`A event category is already registered for ${name}`,
);
}
categories[name] = eventCategory();

Expand Down
88 changes: 44 additions & 44 deletions test/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import events from "../src/eventManager.js"; // eslint-disable-line consistent-d
describe("events", () => {
it("bind callback to event", () => {
// Arrange: an event
let anEvent = event();
let spy = vi.fn();
const anEvent = event();
const spy = vi.fn();

// Act: bind a callback
anEvent.register(spy);
Expand All @@ -21,9 +21,9 @@ describe("events", () => {

it("bind multiple callbacks to an event", () => {
// Arrange: an event
let anEvent = event();
let spy1 = vi.fn();
let spy2 = vi.fn();
const anEvent = event();
const spy1 = vi.fn();
const spy2 = vi.fn();

// Act: bind two callbacks and trigger event
anEvent.register(spy1);
Expand All @@ -38,9 +38,9 @@ describe("events", () => {

it("bind same callback only once", () => {
// Arrange: an event
let anEvent = event();
const anEvent = event();

let spy = vi.fn();
const spy = vi.fn();

// Act: bind two callbacks and trigger event
anEvent.register(spy);
Expand All @@ -54,9 +54,9 @@ describe("events", () => {

it("bind same callback with anonymous functions", () => {
// Arrange: an event
let anEvent = event();
const anEvent = event();

let spy = vi.fn();
const spy = vi.fn();

// Act: bind two callbacks and trigger event
anEvent.register(() => {
Expand All @@ -75,9 +75,9 @@ describe("events", () => {

it("trigger pass values to callbacks", () => {
// Arrange: an event
let anEvent = event();
let spy1 = vi.fn();
let spy2 = vi.fn();
const anEvent = event();
const spy1 = vi.fn();
const spy2 = vi.fn();

// Act: bind two callbacks and trigger event
anEvent.register(spy1);
Expand All @@ -92,11 +92,11 @@ describe("events", () => {

it("un-Bind callback using unregister", () => {
// Arrange: an event
let anEvent = event();
let spy = vi.fn();
const anEvent = event();
const spy = vi.fn();

// bind a callback
let eventBinding = anEvent.register(spy);
const eventBinding = anEvent.register(spy);

// unbind
anEvent.unregister(eventBinding);
Expand All @@ -108,11 +108,11 @@ describe("events", () => {

it("un-Bind callback using unbind", () => {
// Arrange: an event
let anEvent = event();
let spy = vi.fn();
const anEvent = event();
const spy = vi.fn();

// bind a callback
let eventBinding = anEvent.register(spy);
const eventBinding = anEvent.register(spy);

// Unbind
eventBinding.unbind();
Expand All @@ -124,8 +124,8 @@ describe("events", () => {

it("bind and trigger callback only once using registerOnce", () => {
// Arrange: an event
let anEvent = event();
let spy = vi.fn();
const anEvent = event();
const spy = vi.fn();

// Act: bind a callback
anEvent.registerOnce(spy);
Expand All @@ -139,11 +139,11 @@ describe("events", () => {

it("event dispose unbinds all callbacks", () => {
// Arrange: an event
let anEvent = event();
const anEvent = event();

// Act: bind two callbacks and trigger event
let firstBinding = anEvent.register(() => {});
let secondBinding = anEvent.register(() => {});
const firstBinding = anEvent.register(() => {});
const secondBinding = anEvent.register(() => {});

anEvent.dispose();

Expand All @@ -154,9 +154,9 @@ describe("events", () => {

it("event Category keeps a list of events", () => {
// Act: create an event handler ans some events
let someEvents = eventCategory();
let anEvent = someEvents.createEvent();
let anotherEvent = someEvents.createEvent();
const someEvents = eventCategory();
const anEvent = someEvents.createEvent();
const anotherEvent = someEvents.createEvent();

// Assert: events created
expect(anEvent.register).toBeTruthy();
Expand All @@ -165,8 +165,8 @@ describe("events", () => {

it("event Category can keep named events", () => {
// Act: create an event handler ans some events
let someEvents = eventCategory();
let anEvent = someEvents.createEvent("namedEvent");
const someEvents = eventCategory();
const anEvent = someEvents.createEvent("namedEvent");

// Assert: events created
expect(anEvent.register).toBeTruthy();
Expand All @@ -176,8 +176,8 @@ describe("events", () => {
expect.assertions(1);

// Arrange: an event
let someEvents = eventCategory();
let anEvent = someEvents.createEvent("namedEvent");
const someEvents = eventCategory();
const anEvent = someEvents.createEvent("namedEvent");

// bind a callback
someEvents.register("namedEvent", () => {
Expand All @@ -190,12 +190,12 @@ describe("events", () => {

it("event Category can un-bind named event callbacks using unregister", () => {
// Arrange: an event
let someEvents = eventCategory();
let anEvent = someEvents.createEvent("namedEvent");
let spy = vi.fn();
const someEvents = eventCategory();
const anEvent = someEvents.createEvent("namedEvent");
const spy = vi.fn();

// bind a callback
let eventBinding = someEvents.register("namedEvent", spy);
const eventBinding = someEvents.register("namedEvent", spy);

// unbind
someEvents.unregister("namedEvent", eventBinding);
Expand All @@ -207,9 +207,9 @@ describe("events", () => {

it("event Category can bind and trigger named event callback only once using registerOnce", () => {
// Arrange: an event
let someEvents = eventCategory();
let anEvent = someEvents.createEvent("namedEvent");
let spy = vi.fn();
const someEvents = eventCategory();
const anEvent = someEvents.createEvent("namedEvent");
const spy = vi.fn();

// Act: bind a callback
someEvents.registerOnce("namedEvent", spy);
Expand All @@ -223,15 +223,15 @@ describe("events", () => {

it("event Category can bind dispose unbinds all events and there callbacks", () => {
// Arrange: two events in a event handler
let someEvents = eventCategory();
let anEvent = someEvents.createEvent("namedEvent");
let anotherEvent = someEvents.createEvent("namedEvent");
const someEvents = eventCategory();
const anEvent = someEvents.createEvent("namedEvent");
const anotherEvent = someEvents.createEvent("namedEvent");

// Act: bind two callbacks and trigger event
let firstBinding = anEvent.register(() => {});
let secondBinding = anEvent.register(() => {});
let thirdBinding = anotherEvent.register(() => {});
let fourthBinding = anotherEvent.register(() => {});
const firstBinding = anEvent.register(() => {});
const secondBinding = anEvent.register(() => {});
const thirdBinding = anotherEvent.register(() => {});
const fourthBinding = anotherEvent.register(() => {});

someEvents.dispose();

Expand Down
Loading

0 comments on commit 27e1739

Please sign in to comment.