summaryrefslogtreecommitdiff
path: root/ext/broadcast_channel/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/broadcast_channel/lib.rs')
-rw-r--r--ext/broadcast_channel/lib.rs62
1 files changed, 19 insertions, 43 deletions
diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs
index 14884e99c..3df11566f 100644
--- a/ext/broadcast_channel/lib.rs
+++ b/ext/broadcast_channel/lib.rs
@@ -2,7 +2,6 @@
mod in_memory_broadcast_channel;
-use deno_core::ExtensionBuilder;
pub use in_memory_broadcast_channel::InMemoryBroadcastChannel;
pub use in_memory_broadcast_channel::InMemoryBroadcastChannelResource;
@@ -12,9 +11,7 @@ use std::rc::Rc;
use async_trait::async_trait;
use deno_core::error::AnyError;
-use deno_core::include_js_files;
use deno_core::op;
-use deno_core::Extension;
use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
@@ -107,46 +104,25 @@ where
bc.recv(&resource).await
}
-fn ext() -> ExtensionBuilder {
- Extension::builder_with_deps(
- env!("CARGO_PKG_NAME"),
- &["deno_webidl", "deno_web"],
- )
-}
-
-fn ops<BC: BroadcastChannel + 'static>(
- ext: &mut ExtensionBuilder,
- bc: BC,
- unstable: bool,
-) -> &mut ExtensionBuilder {
- ext
- .ops(vec![
- op_broadcast_subscribe::decl::<BC>(),
- op_broadcast_unsubscribe::decl::<BC>(),
- op_broadcast_send::decl::<BC>(),
- op_broadcast_recv::decl::<BC>(),
- ])
- .state(move |state| {
- state.put(bc.clone());
- state.put(Unstable(unstable));
- })
-}
-
-pub fn init_ops_and_esm<BC: BroadcastChannel + 'static>(
- bc: BC,
- unstable: bool,
-) -> Extension {
- ops::<BC>(&mut ext(), bc, unstable)
- .esm(include_js_files!("01_broadcast_channel.js",))
- .build()
-}
-
-pub fn init_ops<BC: BroadcastChannel + 'static>(
- bc: BC,
- unstable: bool,
-) -> Extension {
- ops::<BC>(&mut ext(), bc, unstable).build()
-}
+deno_core::extension!(deno_broadcast_channel,
+ deps = [ deno_webidl, deno_web ],
+ parameters = [BC: BroadcastChannel],
+ ops = [
+ op_broadcast_subscribe<BC>,
+ op_broadcast_unsubscribe<BC>,
+ op_broadcast_send<BC>,
+ op_broadcast_recv<BC>,
+ ],
+ esm = [ "01_broadcast_channel.js" ],
+ config = {
+ bc: BC,
+ unstable: bool,
+ },
+ state = |state, bc, unstable| {
+ state.put(bc);
+ state.put(Unstable(unstable));
+ },
+);
pub fn get_declaration() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))