Skip to content

Commit

Permalink
Add our own max function
Browse files Browse the repository at this point in the history
And remove lodash-max
  • Loading branch information
tvdeyen committed Jan 8, 2024
1 parent d589663 commit ae15cdc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/javascript/alchemy_admin/picture_editors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debounce from "alchemy_admin/utils/debounce"
import max from "lodash-es/max"
import max from "alchemy_admin/utils/max"
import { get } from "alchemy_admin/utils/ajax"
import ImageLoader from "alchemy_admin/image_loader"

Expand Down
3 changes: 3 additions & 0 deletions app/javascript/alchemy_admin/utils/max.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function (a, b) {
return a >= b ? a : b
}
1 change: 0 additions & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pin "@ungap/custom-elements", to: "https://ga.jspm.io/npm:@ungap/custom-elements@1.3.0/index.js", preload: true
pin "flatpickr", to: "https://ga.jspm.io/npm:flatpickr@4.6.13/dist/esm/index.js", preload: true
pin "lodash-es/max", to: "https://ga.jspm.io/npm:lodash-es@4.17.21/max.js", preload: true
pin "sortablejs", to: "https://ga.jspm.io/npm:sortablejs@1.15.1/modular/sortable.esm.js", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@shoelace/animation-registry", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.12.0/cdn/utilities/animation-registry.js", preload: true
Expand Down
21 changes: 21 additions & 0 deletions spec/javascript/alchemy_admin/utils/max.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import max from "alchemy_admin/utils/max.js"

describe("max", () => {
it("should return the maximum value between two numbers", () => {
expect(max(2, 5)).toBe(5)
expect(max(-10, 0)).toBe(0)
expect(max(100, 100)).toBe(100)
})

it("should return the maximum value between two negative numbers", () => {
expect(max(-5, -2)).toBe(-2)
expect(max(-10, -10)).toBe(-10)
expect(max(-100, -50)).toBe(-50)
})

it("should return the maximum value between a positive and a negative number", () => {
expect(max(5, -2)).toBe(5)
expect(max(-10, 10)).toBe(10)
expect(max(-100, 50)).toBe(50)
})
})

0 comments on commit ae15cdc

Please sign in to comment.