Skip to content

Commit

Permalink
chore: remove deprecated fns, updated deprecated attr syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Nov 16, 2023
1 parent f47d54b commit 2804b0b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 62 deletions.
58 changes: 1 addition & 57 deletions src/lib.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Source webview C library: https://github.com/webview/webview
module webview

import icon
import json

// Webview is a pointer to a webview instance.
pub type Webview = C.webview_t
Expand All @@ -25,7 +24,7 @@ pub:
args &char
}

[params]
@[params]
pub struct CreateOptions {
debug ?bool
window voidptr
Expand Down Expand Up @@ -177,19 +176,6 @@ pub fn (w &Webview) bind_opt[T](name string, func fn (&Event) !T) {
}, 0)
}

// bind_ctx binds a V callback to a global JavaScript function that will appear under the given name.
// The callback receives an `&Event` and a user-provided ctx pointer argument.
[deprecated: 'will be removed with v0.7; use `bind_with_ctx` instead.']
pub fn (w &Webview) bind_ctx[T](name string, func fn (e &Event, ctx voidptr) T, ctx voidptr) {
C.webview_bind(w, &char(name.str), fn [w, func] [T](event_id &char, args &char, ctx voidptr) {
e := unsafe { &Event{w, event_id, args} }
spawn fn [func, ctx] [T](e &Event) {
result := func(e, ctx)
e.@return(result, .value)
}(e.async())
}, ctx)
}

// bind_with_ctx binds a V callback to a global JavaScript function that will appear under the given name.
// The callback receives an `&Event` and a user-provided ctx pointer argument.
pub fn (w &Webview) bind_with_ctx[T](name string, func fn (e &Event, ctx voidptr) T, ctx voidptr) {
Expand Down Expand Up @@ -261,45 +247,3 @@ pub fn (e &Event) get_arg[T](idx int) !T {
return e.get_complex_args_json[T](idx)!
}
}

// string parses the JavaScript argument with the given index as string.
[deprecated: 'will be removed with v0.7; use `get_arg[T](idx int) !T` instead. E.g: `e.get_arg[string](0)!`']
pub fn (e &Event) string(idx usize) string {
return e.args_json[string]() or { return '' }[int(idx)] or { '' }
}

// int parses the JavaScript argument with the given index as integer.
[deprecated: 'will be removed with v0.7; use `get_arg[T](idx int) !T` instead. E.g: `e.get_arg[int](0)!`']
pub fn (e &Event) int(idx usize) int {
return e.args_json[int]() or { return 0 }[int(idx)] or { return 0 }
}

// bool parses the JavaScript argument with the given index as boolean.
[deprecated: 'will be removed with v0.7; use `get_arg[T](idx int) !T` instead. E.g: `e.get_arg[bool](0)!`']
pub fn (e &Event) bool(idx usize) bool {
return e.args_json[bool]() or { return false }[int(idx)] or { return false }
}

// string_opt parses the JavaScript argument with the given index as string option.
[deprecated: 'will be removed with v0.7; use `get_arg[T](idx int) !T` instead. E.g: `e.get_arg[string](0)!`']
pub fn (e &Event) string_opt(idx usize) ?string {
return e.args_json[string]() or { return none }[int(idx)] or { return none }
}

// int_opt parses the JavaScript argument with the given index as integer option.
[deprecated: 'will be removed with v0.7; use `get_arg[T](idx int) !T` instead. E.g: `e.get_arg[int](0)!`']
pub fn (e &Event) int_opt(idx usize) ?int {
return e.args_json[int]() or { return none }[int(idx)] or { return none }
}

// bool_opt parses and return the argument with the given index as boolean option.
[deprecated: 'will be removed with v0.7; use `get_arg[T](idx int) !T` instead. E.g: `e.get_arg[bool](0)!`']
pub fn (e &Event) bool_opt(idx usize) ?bool {
return e.args_json[bool]() or { return none }[int(idx)] or { return none }
}

// decode parses the JavaScript argument with the given index into a V data type.
[deprecated: 'will be removed with v0.7; use `get_arg[T](idx int) !T` instead. E.g: `e.get_arg[MyStruct](0)!`']
pub fn (e &Event) decode[T](idx usize) !T {
return json.decode(T, e.string(idx)) or { return error('Failed decoding arguments. ${err}') }
}
5 changes: 0 additions & 5 deletions src/utils.v
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,3 @@ fn (e &Event) get_complex_args_json[T](idx int) !T {
return error('Failed finding argument of type `${T.name}` at index `${idx}`')
}) or { return error('Failed decoding argument of type `${T.name}` at index `${idx}`. ${err}') }
}

[deprecated]
fn (e &Event) args_json[T]() ![]T {
return json.decode([]T, unsafe { e.args.vstring() })!
}

0 comments on commit 2804b0b

Please sign in to comment.