Skip to content

Pipe as the first agument instead of the last. #571

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

Merged
merged 9 commits into from
Jan 25, 2023
Merged
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
229 changes: 117 additions & 112 deletions core/source/Array.mint

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions core/source/Dom.mint
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module Dom {
Returns if the given element is in an element that matches the given
selector.

Dom.containedInSelector("body", Dom.getElementBySelector("div"))
Dom.containedInSelector(Dom.getElementBySelector("div"), "body")
*/
fun containedInSelector (selector : String, element : Dom.Element) : Bool {
fun containedInSelector (element : Dom.Element, selector : String) : Bool {
`
(() => {
for (let base of document.querySelectorAll(selector)) {
Expand All @@ -32,9 +32,9 @@ module Dom {
/*
Returns if the given base element contains the given element.

Dom.contains(div, body) == true
Dom.contains(body, div) == true
*/
fun contains (element : Dom.Element, base : Dom.Element) : Bool {
fun contains (base : Dom.Element, element : Dom.Element) : Bool {
`#{base}.contains(#{element})`
}

Expand All @@ -54,11 +54,11 @@ module Dom {
}
*/
fun containsMaybe (
maybeElement : Maybe(Dom.Element),
base : Dom.Element
base : Dom.Element,
maybeElement : Maybe(Dom.Element)
) : Bool {
maybeElement
|> Maybe.map((item : Dom.Element) { Dom.contains(item, base) })
|> Maybe.map((item : Dom.Element) { Dom.contains(base, item) })
|> Maybe.withDefault(false)
}

Expand Down Expand Up @@ -155,11 +155,11 @@ module Dom {
Dom.getElementById("my-div")

case (outcome) {
Maybe::Just(element) => Dom.getAttribute("id", element) == "my-div"
Maybe::Just(element) => Dom.getAttribute(element, "id") == "my-div"
Maybe::Nothing => false
}
*/
fun getAttribute (name : String, element : Dom.Element) : Maybe(String) {
fun getAttribute (element : Dom.Element, name : String) : Maybe(String) {
`
(() => {
const value = #{element}.getAttribute(#{name})
Expand Down Expand Up @@ -286,9 +286,9 @@ module Dom {
const element = document.elementFromPoint(#{left}, #{top})

if (element) {
return new Just(element)
return #{Maybe::Just(`element`)}
} else {
return new Nothing()
return #{Maybe::Nothing}
}
})()
`
Expand All @@ -298,9 +298,9 @@ module Dom {
Gets all descendant elements of an element which are matching
the given selector.

Dom.getElementsBySelector("a[name]", element)
Dom.getElementsBySelector(element, "a[name]")
*/
fun getElementsBySelector (selector : String, element : Dom.Element) : Array(Dom.Element) {
fun getElementsBySelector (element : Dom.Element, selector : String) : Array(Dom.Element) {
`Array.from(#{element}.querySelectorAll(#{selector}))`
}

Expand Down Expand Up @@ -390,13 +390,13 @@ module Dom {
/*
Returns the table of contents of the given element for the given selectors.

Dom.getTableOfContents("h1, h2, h3, h4", element) == [
Dom.getTableOfContents(element, "h1, h2, h3, h4") == [
{"h1", "The title of the page", "the-title-of-the-page"},
{"h2", "A subtitle of the page", "a-subtitle-of-the-page"},
{"h3", "A sub-subtitle of the page", "a-sub-subtitle-of-the-page"}
]
*/
fun getTableOfContents (selector : String, element : Dom.Element) : Array(Tuple(String, String, String)) {
fun getTableOfContents (element : Dom.Element, selector : String) : Array(Tuple(String, String, String)) {
element
|> getElementsBySelector(selector)
|> Array.map(
Expand Down Expand Up @@ -439,9 +439,9 @@ module Dom {
/*
Measures the given text width with the given font using the canvas.

Dom.getTextWidth("20px sans-serif", "Hello There") = 300
Dom.getTextWidth("Hello There", "20px sans-serif") = 300
*/
fun getTextWidth (font : String, text : String) : Number {
fun getTextWidth (text : String, font : String) : Number {
`
(() => {
const canvas = document.createElement('canvas');
Expand Down Expand Up @@ -480,10 +480,10 @@ module Dom {
/*
Returns whether or not the given `Dom.Element` matches the given selector.

Dom.matches("div", Dom.createElement("div")) == true
Dom.matches("p", Dom.createElement("div")) == false
Dom.matches(Dom.createElement("div"), "div") == true
Dom.matches(Dom.createElement("div"), "p") == false
*/
fun matches (selector : String, dom : Dom.Element) : Bool {
fun matches (dom : Dom.Element, selector : String) : Bool {
`
(() => {
try {
Expand Down Expand Up @@ -516,9 +516,9 @@ module Dom {
|> Dom.setAttribute("name", "test")
*/
fun setAttribute (
element : Dom.Element,
attribute : String,
value : String,
element : Dom.Element
value : String
) : Dom.Element {
`#{element}.setAttribute(#{attribute}, #{value}) && element`
}
Expand All @@ -531,7 +531,7 @@ module Dom {
|> Dom.setStyle("background", "red")
|> Dom.setStyle("color", "white")
*/
fun setStyle (name : String, value : String, element : Dom.Element) : Dom.Element {
fun setStyle (element : Dom.Element, name : String, value : String) : Dom.Element {
`
(() => {
#{element}.style[#{name}] = #{value}
Expand All @@ -545,7 +545,7 @@ module Dom {

It is used to set the value of `input` fields programmatically.
*/
fun setValue (value : String, dom : Dom.Element) : Dom.Element {
fun setValue (dom : Dom.Element, value : String) : Dom.Element {
`(#{dom}.value = #{value}) && #{dom}`
}

Expand Down
4 changes: 2 additions & 2 deletions core/source/FormData.mint
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module FormData {
|> FormData.addFile(
"key", File.fromString("Contents", "text.txt", "text/plain"))
*/
fun addFile (key : String, value : File, formData : FormData) : FormData {
fun addFile (formData : FormData, key : String, value : File) : FormData {
`
(() => {
var newFormData = new FormData();
Expand All @@ -35,7 +35,7 @@ module FormData {
FormData.empty()
|> FormData.addString("key", "value")
*/
fun addString (key : String, value : String, formData : FormData) : FormData {
fun addString (formData : FormData, key : String, value : String) : FormData {
`
(() => {
var newFormData = new FormData();
Expand Down
8 changes: 4 additions & 4 deletions core/source/Function.mint
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module Function {
/*
Debounces a function without arguments.

Function.debounce(() { Debug.log("Hello World!") })
Function.debounce(() { Debug.log("Hello World!") }, 100)
*/
fun debounce (delay : Number, method : Function(a)) : Function(a) {
fun debounce (method : Function(a), delay : Number) : Function(a) {
`
(() => {
let _id;
Expand All @@ -20,9 +20,9 @@ module Function {
/*
Debounces a function with only one argument.

Function.debounce1((argument : String) { Debug.log(argument) })
Function.debounce1((argument : String) { Debug.log(argument) }, 100)
*/
fun debounce1 (delay : Number, method : Function(a, b)) : Function(a, b) {
fun debounce1 (method : Function(a, b), delay : Number) : Function(a, b) {
`
(() => {
let _id;
Expand Down
14 changes: 7 additions & 7 deletions core/source/Html/DataTransfer.mint
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Html.DataTransfer {
}

/* Returns string data for the given format or an empty string if there is no data. */
fun getData (format : String, data : Html.DataTransfer) : String {
fun getData (data : Html.DataTransfer, format : String) : String {
`#{data}.getData(#{format})`
}

Expand All @@ -37,30 +37,30 @@ module Html.DataTransfer {

/* Sets the data fro the data transfer. */
fun setData (
data : Html.DataTransfer,
format : String,
value : String,
data : Html.DataTransfer
value : String
) : Html.DataTransfer {
`#{data}.setData(#{format}, #{value}) || #{data}`
}

/* Sets the element as the drag image of the data transfer. */
fun setDragImage (
data : Html.DataTransfer,
element : Dom.Element,
offsetX : Number,
offsetY : Number,
data : Html.DataTransfer
offsetY : Number
) : Html.DataTransfer {
`#{data}.setDragImage(#{element}, #{offsetX}, #{offsetY}) || #{data}`
}

/* Sets the operation to a new type. The value must be `none`, `copy`, `link` or `move`. */
fun setDropEffect (value : String, data : Html.DataTransfer) : Html.DataTransfer {
fun setDropEffect (data : Html.DataTransfer, value : String) : Html.DataTransfer {
`(#{data}.dropEffect = #{value}) && #{data}`
}

/* Sets of the type of operation that are possible. */
fun setEffectAllowed (value : String, data : Html.DataTransfer) : Html.DataTransfer {
fun setEffectAllowed (data : Html.DataTransfer, value : String) : Html.DataTransfer {
`(#{data}.effectAllowed = #{value}) && #{data}`
}
}
22 changes: 11 additions & 11 deletions core/source/Http.mint
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module Http {
|> Http.formDataBody(formData)
|> Http.send()
*/
fun formDataBody (body : FormData, request : Http.Request) : Http.Request {
fun formDataBody (request : Http.Request, body : FormData) : Http.Request {
{ request | body: `#{body}` }
}

Expand All @@ -148,7 +148,7 @@ module Http {
|> Http.header("Content-Type", "application/json")
|> Http.hasHeader("Content-Type")
*/
fun hasHeader (key : String, request : Http.Request) : Bool {
fun hasHeader (request : Http.Request, key : String) : Bool {
request.headers
|> Array.any(
(header : Http.Header) : Bool {
Expand All @@ -162,7 +162,7 @@ module Http {
Http.empty()
|> Http.header("Content-Type", "application/json")
*/
fun header (key : String, value : String, request : Http.Request) : Http.Request {
fun header (request : Http.Request, key : String, value : String) : Http.Request {
{ request |
headers:
request.headers
Expand All @@ -186,8 +186,8 @@ module Http {
|> Http.jsonBody(encode { name = "John" })
|> Http.send()
*/
fun jsonBody (body : Object, request : Http.Request) : Http.Request {
if (hasHeader("Content-Type", request)) {
fun jsonBody (request : Http.Request, body : Object) : Http.Request {
if (hasHeader(request, "Content-Type")) {
{ request | body: `JSON.stringify(#{body})` }
} else {
{ request | body: `JSON.stringify(#{body})` }
Expand All @@ -201,7 +201,7 @@ module Http {
Http.empty()
|> Http.method("PATCH")
*/
fun method (method : String, request : Http.Request) : Http.Request {
fun method (request : Http.Request, method : String) : Http.Request {
{ request | method: method }
}

Expand Down Expand Up @@ -246,7 +246,7 @@ module Http {
|> Http.send()
*/
fun send (request : Http.Request) : Promise(Result(Http.ErrorResponse, Http.Response)) {
sendWithId(Uid.generate(), request)
sendWithId(request, Uid.generate())
}

/*
Expand All @@ -256,7 +256,7 @@ module Http {
|> Http.get()
|> Http.sendWithId("my-request")
*/
fun sendWithId (uid : String, request : Http.Request) : Promise(Result(Http.ErrorResponse, Http.Response)) {
fun sendWithId (request : Http.Request, uid : String) : Promise(Result(Http.ErrorResponse, Http.Response)) {
`
new Promise((resolve, reject) => {
if (!this._requests) { this._requests = {} }
Expand Down Expand Up @@ -335,7 +335,7 @@ module Http {
|> Http.stringBody("Some string that will come back.")
|> Http.send()
*/
fun stringBody (body : String, request : Http.Request) : Http.Request {
fun stringBody (request : Http.Request, body : String) : Http.Request {
{ request | body: `#{body}` }
}

Expand All @@ -345,7 +345,7 @@ module Http {
Http.empty()
|> Http.url("https://httpbin.org/anything")
*/
fun url (url : String, request : Http.Request) : Http.Request {
fun url (request : Http.Request, url : String) : Http.Request {
{ request | url: url }
}

Expand All @@ -355,7 +355,7 @@ module Http {
Http.empty()
|> Http.withCredentials(true)
*/
fun withCredentials (value : Bool, request : Http.Request) : Http.Request {
fun withCredentials (request : Http.Request, value : Bool) : Http.Request {
{ request | withCredentials: value }
}
}
8 changes: 4 additions & 4 deletions core/source/IntersectionObserver.mint
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ module IntersectionObserver {

/* Observes the given element. */
fun observe (
element : Dom.Element,
observer : IntersectionObserver
observer : IntersectionObserver,
element : Dom.Element
) : IntersectionObserver {
`#{observer}.observe(#{element}) || #{observer}`
}

/* Unobserves the given element. */
fun unobserve (
element : Dom.Element,
observer : IntersectionObserver
observer : IntersectionObserver,
element : Dom.Element
) : IntersectionObserver {
`#{observer}.unobserve(#{element}) || #{observer}`
}
Expand Down
Loading