-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial implementation of Event (#637)
* feat: Initial implementation of Event * Delete limetime * Fix
- Loading branch information
1 parent
977ef7f
commit 7f0ff52
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use rquickjs::{prelude::Opt, Result, Value}; | ||
|
||
use llrt_utils::object::ObjectExt; | ||
|
||
#[rquickjs::class] | ||
#[derive(rquickjs::class::Trace)] | ||
pub struct Event { | ||
event_type: String, | ||
bubbles: bool, | ||
cancelable: bool, | ||
composed: bool, | ||
} | ||
|
||
#[rquickjs::methods] | ||
impl Event { | ||
#[qjs(constructor)] | ||
pub fn new(event_type: String, options: Opt<Value<'_>>) -> Result<Self> { | ||
let mut bubbles = false; | ||
let mut cancelable = false; | ||
let mut composed = false; | ||
if let Some(options) = options.0 { | ||
if let Some(opt) = options.get_optional("bubbles")? { | ||
bubbles = opt; | ||
} | ||
if let Some(opt) = options.get_optional("cancelable")? { | ||
cancelable = opt; | ||
} | ||
if let Some(opt) = options.get_optional("composed")? { | ||
composed = opt; | ||
} | ||
} | ||
Ok(Self { | ||
event_type, | ||
bubbles, | ||
cancelable, | ||
composed, | ||
}) | ||
} | ||
|
||
#[qjs(get)] | ||
pub fn bubbles(&self) -> bool { | ||
self.bubbles | ||
} | ||
|
||
#[qjs(get)] | ||
pub fn cancelable(&self) -> bool { | ||
self.cancelable | ||
} | ||
|
||
#[qjs(get)] | ||
pub fn composed(&self) -> bool { | ||
self.composed | ||
} | ||
|
||
#[qjs(get, rename = "type")] | ||
pub fn event_type(&self) -> String { | ||
self.event_type.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters