Giter VIP home page Giter VIP logo

js_bindings's Introduction

This is (or should be) a full JavaScript interop package using package:js bindings.

The bindings are generated by machine-reading WebIDL files for types and MDN website for documentation.

Take a look at MediaStream file and check out how nice it got with the awesome MDN documentation.

Usage

import 'package:js_bindings/js_bindings.dart';

void main() {
  var div = document.createElement('div')
    ..innerHTML = 'Hello world =]';
  
  document.body!.appendChild(div);
}

Check the example tab for a more complete example.

Promise and Future

JS Promises and Dart Futures are different things.
But this package make them the same! :D

import 'package:js_bindings/js_bindings.dart';

Future<void> main() async {
  // you can await like regular future
  await window.navigator.mediaDevices.getUserMedia();
  // or 
  window.navigator.mediaDevices.getUserMedia().then((event) {});
}

Enums

Enums like document.visibilityState are Strings in JS world, but here we work with enums instead. For example document.visibilityState is of type VisibilityState, which is a Enum.
So all of what is specificied in the W3C IDL files as enums are in fact enums in this package.

Variadic args

Dart doesn't have the concept of variadic args as JS, so we can't make a one to one there. However, we made it that variadic arguments are multiplied to 3 optional args of same type.
Example: window.console.log(1, 2, 3) - In this case all arguments are dynamic.

Todo:

For a better JS interop

If you wish for a better JS interop in Dart, please, thumbs up the following issues:

Better JS interop in general

Donation

What about a coffee?

Donate

js_bindings's People

Contributors

jodinathan avatar kevmoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.