Skip to content

Commit

Permalink
rename ffi file
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer authored and lpil committed Jun 26, 2024
1 parent 2cf699d commit fb8719b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Renamed ffi file to be scope with project name.

## v0.10.0 - 2024-06-23

- The `Reference` type has been deprecated.
Expand Down
12 changes: 6 additions & 6 deletions src/gleam/javascript.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub type Symbol
/// For further information view the MDN documentation:
/// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol>
///
@external(javascript, "../ffi.mjs", "type_of")
@external(javascript, "../gleam_javascript_ffi.mjs", "type_of")
pub fn type_of(a: value) -> TypeOf

/// Use the JavaScript `Symbol.for` method to look up a symbol with the given
Expand All @@ -42,22 +42,22 @@ pub fn type_of(a: value) -> TypeOf
/// For further information see the MDN documentation:
/// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for>
///
@external(javascript, "../ffi.mjs", "get_symbol")
@external(javascript, "../gleam_javascript_ffi.mjs", "get_symbol")
pub fn get_symbol(a: String) -> Symbol

@deprecated("The Reference type is being removed from this packge")
pub type Reference(value)

@deprecated("The Reference type is being removed from this packge")
@external(javascript, "../ffi.mjs", "dereference")
@external(javascript, "../gleam_javascript_ffi.mjs", "dereference")
pub fn dereference(a: Reference(a)) -> a

@deprecated("The Reference type is being removed from this packge")
@external(javascript, "../ffi.mjs", "set_reference")
@external(javascript, "../gleam_javascript_ffi.mjs", "set_reference")
pub fn set_reference(a: Reference(a), b: a) -> a

@deprecated("The Reference type is being removed from this packge")
@external(javascript, "../ffi.mjs", "make_reference")
@external(javascript, "../gleam_javascript_ffi.mjs", "make_reference")
pub fn make_reference(a: a) -> Reference(a)

@deprecated("The Reference type is being removed from this packge")
Expand All @@ -68,5 +68,5 @@ pub fn update_reference(ref: Reference(a), f: fn(a) -> a) -> a {
}

@deprecated("The Reference type is being removed from this packge")
@external(javascript, "../ffi.mjs", "reference_equal")
@external(javascript, "../gleam_javascript_ffi.mjs", "reference_equal")
pub fn reference_equal(a: Reference(a), b: Reference(a)) -> Bool
12 changes: 6 additions & 6 deletions src/gleam/javascript/array.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ pub fn to_list(a: Array(element)) -> List(element)
///
/// Runs in linear time.
///
@external(javascript, "../../ffi.mjs", "toArray")
@external(javascript, "../../gleam_javascript_ffi.mjs", "toArray")
pub fn from_list(a: List(element)) -> Array(element)

/// Get the number of elements in the array.
///
/// Runs in constant time.
///
@external(javascript, "../../ffi.mjs", "length")
@external(javascript, "../../gleam_javascript_ffi.mjs", "length")
pub fn size(a: Array(element)) -> Int

/// Returns a new array containing only the elements of the first array after
Expand All @@ -37,7 +37,7 @@ pub fn size(a: Array(element)) -> Int
/// from_list([4, 8, 12])
/// ```
///
@external(javascript, "../../ffi.mjs", "map")
@external(javascript, "../../gleam_javascript_ffi.mjs", "map")
pub fn map(a: Array(a), with with: fn(a) -> b) -> Array(b)

/// Reduces a list of elements into a single value by calling a given function
Expand All @@ -48,7 +48,7 @@ pub fn map(a: Array(a), with with: fn(a) -> b) -> Array(b)
///
/// Runs in linear time.
///
@external(javascript, "../../ffi.mjs", "reduce")
@external(javascript, "../../gleam_javascript_ffi.mjs", "reduce")
pub fn fold(over over: Array(e), from from: a, with with: fn(a, e) -> a) -> a

/// Reduces a list of elements into a single value by calling a given function
Expand All @@ -59,7 +59,7 @@ pub fn fold(over over: Array(e), from from: a, with with: fn(a, e) -> a) -> a
///
/// Runs in linear time.
///
@external(javascript, "../../ffi.mjs", "reduceRight")
@external(javascript, "../../gleam_javascript_ffi.mjs", "reduceRight")
pub fn fold_right(
over over: Array(e),
from from: a,
Expand All @@ -80,5 +80,5 @@ pub fn fold_right(
/// Error(Nil)
/// ```
///
@external(javascript, "../../ffi.mjs", "index")
@external(javascript, "../../gleam_javascript_ffi.mjs", "index")
pub fn get(a: Array(e), b: Int) -> Result(e, Nil)
8 changes: 4 additions & 4 deletions src/gleam/javascript/map.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ pub type Map(key, value)

/// Create a new `Map` with no contained values.
///
@external(javascript, "../../ffi.mjs", "map_new")
@external(javascript, "../../gleam_javascript_ffi.mjs", "map_new")
pub fn new() -> Map(key, value)

/// Insert a new key and value into the `Map`.
///
/// **NOTE:** This function will mutate the `Map` rather than immutably
/// updating it.
///
@external(javascript, "../../ffi.mjs", "map_set")
@external(javascript, "../../gleam_javascript_ffi.mjs", "map_set")
pub fn set(a: Map(key, value), b: key, c: value) -> Map(key, value)

/// Get the value for a given key in the `Map`.
///
@external(javascript, "../../ffi.mjs", "map_get")
@external(javascript, "../../gleam_javascript_ffi.mjs", "map_get")
pub fn get(a: Map(key, value), b: key) -> Result(value, Nil)

/// Get the number of key-value pairs in the `Map`.
///
@external(javascript, "../../ffi.mjs", "map_size")
@external(javascript, "../../gleam_javascript_ffi.mjs", "map_size")
pub fn size(a: Map(key, value)) -> Int
38 changes: 19 additions & 19 deletions src/gleam/javascript/promise.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ pub type Promise(value)
/// This function is useful for converting code that uses callbacks into code
/// that uses promises.
///
@external(javascript, "../../ffi.mjs", "newPromise")
@external(javascript, "../../gleam_javascript_ffi.mjs", "newPromise")
pub fn new(a: fn(fn(value) -> Nil) -> Nil) -> Promise(value)

/// Create a promise that resolves immediately.
///
@external(javascript, "../../ffi.mjs", "resolve")
@external(javascript, "../../gleam_javascript_ffi.mjs", "resolve")
pub fn resolve(a: value) -> Promise(value)

/// If the promise is in an error state then apply a function to convert the
/// error value back into valid value, making the promise healthy again.
///
/// This is the equivilent of the `promise.catch` JavaScript method.
///
@external(javascript, "../../ffi.mjs", "rescue")
@external(javascript, "../../gleam_javascript_ffi.mjs", "rescue")
pub fn rescue(a: Promise(value), b: fn(Dynamic) -> value) -> Promise(value)

/// Chain a second asynchronous operation onto a promise, so it runs after the
/// promise has resolved.
///
/// This is the equivilent of the `promise.then` JavaScript method.
///
@external(javascript, "../../ffi.mjs", "then")
@external(javascript, "../../gleam_javascript_ffi.mjs", "then")
pub fn await(a: Promise(a), b: fn(a) -> Promise(b)) -> Promise(b)

/// Run a function on the value a promise resolves to, after it has resolved.
/// The value returned becomes the new value contained by the promise.
///
@external(javascript, "../../ffi.mjs", "map_promise")
@external(javascript, "../../gleam_javascript_ffi.mjs", "map_promise")
pub fn map(a: Promise(a), b: fn(a) -> b) -> Promise(b)

/// Run a function on the value a promise resolves to, after it has resolved.
Expand Down Expand Up @@ -116,15 +116,15 @@ pub fn try_await(
///
/// This is the equivilent of the `Promise.all` JavaScript static method.
///
@external(javascript, "../../ffi.mjs", "all_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
pub fn await2(a: Promise(a), b: Promise(b)) -> Promise(#(a, b))

/// Chain an asynchronous operation onto 3 promises, so it runs after the
/// promises have resolved.
///
/// This is the equivilent of the `Promise.all` JavaScript static method.
///
@external(javascript, "../../ffi.mjs", "all_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
pub fn await3(
a: Promise(a),
b: Promise(b),
Expand All @@ -136,7 +136,7 @@ pub fn await3(
///
/// This is the equivilent of the `Promise.all` JavaScript static method.
///
@external(javascript, "../../ffi.mjs", "all_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
pub fn await4(
a: Promise(a),
b: Promise(b),
Expand All @@ -149,7 +149,7 @@ pub fn await4(
///
/// This is the equivilent of the `Promise.all` JavaScript static method.
///
@external(javascript, "../../ffi.mjs", "all_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
pub fn await5(
a: Promise(a),
b: Promise(b),
Expand All @@ -163,7 +163,7 @@ pub fn await5(
///
/// This is the equivilent of the `Promise.all` JavaScript static method.
///
@external(javascript, "../../ffi.mjs", "all_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
pub fn await6(
a: Promise(a),
b: Promise(b),
Expand All @@ -178,7 +178,7 @@ pub fn await6(
///
/// This is the equivilent of the `Promise.all` JavaScript static method.
///
@external(javascript, "../../ffi.mjs", "all_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
pub fn await_array(a: Array(Promise(a))) -> Promise(Array(a))

/// Chain an asynchronous operation onto an list of promises, so it runs after the
Expand All @@ -192,24 +192,24 @@ pub fn await_list(xs: List(Promise(a))) -> Promise(List(a)) {
|> map(array.to_list)
}

@external(javascript, "../../ffi.mjs", "all_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
fn do_await_list(a: List(Promise(a))) -> Promise(Array(a))

@external(javascript, "../../ffi.mjs", "race_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
pub fn race2(a: Promise(a), b: Promise(a)) -> Promise(a)

@external(javascript, "../../ffi.mjs", "race_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
pub fn race3(a: Promise(a), b: Promise(a), c: Promise(a)) -> Promise(a)

@external(javascript, "../../ffi.mjs", "race_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
pub fn race4(
a: Promise(a),
b: Promise(a),
c: Promise(a),
d: Promise(a),
) -> Promise(a)

@external(javascript, "../../ffi.mjs", "race_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
pub fn race5(
a: Promise(a),
b: Promise(a),
Expand All @@ -218,7 +218,7 @@ pub fn race5(
e: Promise(a),
) -> Promise(a)

@external(javascript, "../../ffi.mjs", "race_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
pub fn race6(
a: Promise(a),
b: Promise(a),
Expand All @@ -228,8 +228,8 @@ pub fn race6(
f: Promise(a),
) -> Promise(a)

@external(javascript, "../../ffi.mjs", "race_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
pub fn race_list(a: List(Promise(a))) -> Promise(a)

@external(javascript, "../../ffi.mjs", "race_promises")
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
pub fn race_array(a: Array(Promise(a))) -> Promise(a)
File renamed without changes.

0 comments on commit fb8719b

Please sign in to comment.