Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: packages/js_util/README.md

Issue 2119523002: Added full js & js_util packages (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/js_util/LICENSE ('k') | packages/js_util/dist/js_util.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/js_util/README.md
diff --git a/packages/js_util/README.md b/packages/js_util/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..412af74a3541ca9475c346c7e08d7153af7a4fec
--- /dev/null
+++ b/packages/js_util/README.md
@@ -0,0 +1,69 @@
+# js_util
+
+[![Build Status](https://travis-ci.org/fluidic/js_util.svg?branch=master)](https://travis-ci.org/fluidic/js_util)
+
+Utilities to access JavaScript from Dart.
+
+* toJS(o): Converts a Dart object to a JavaScript object.
+* newObject(): Creates a new JavaScript object.
+* defineProperty(o, String prop, PropertyDescription desc): A wrapper for [Object.defineProperty][defineProperty]
+* getValue(o, String prop): Returns `o[prop]`.
+* setValue(o, String prop, value): Performs `o[prop] = value`.
+
+These utilities are of great help if a JavaScript API takes a JavaScript object
+with keys that are not fixed because [js][js] package does not let you create a
+JavaScript object without declaring a Dart class with `@JS()` and `@anonymous`.
+
+[defineProperty]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
+[js]: https://pub.dartlang.org/packages/js
+
+## Getting Started
+
+Include `js_util.js` in index.html to use js_util functions.
+
+```html
+<html>
+ <head>
+ <script async src="packages/js_util/dist/js_util.js"></script>
+ <script async src="packages/browser/dart.js"></script>
+ </head>
+</html>
+```
+
+## Usage
+
+A simple usage example:
+
+```dart
+final obj = newObject();
+defineProperty(obj, 'foo', new PropertyDescription(enumerable: true, value: 1));
+defineProperty(obj, 'bar', new PropertyDescription(enumerable: false, value: 2));
+```
+
+```dart
+final obj = newObject();
+setValue(obj, 'foo', 1);
+setValue(obj, 'bar', 2);
+
+print(getValue(obj, 'foo')); // 1
+print(getValue(obj, 'bar')); // 2
+```
+
+```dart
+final jsObj = toJS({
+ 'people': [
+ {'firstName': 'Kwang Yul', 'lastName': 'Seo'},
+ {'firstName': 'DoHyung', 'lastName': 'Kim'},
+ {'firstName': 'Kyusun', 'lastName': 'Kim'}
+ ]
+});
+
+final people = getValue(jsObj, 'people');
+print(getValue(people[0], 'firstName')); // 'Kwang Yul'
+```
+
+## Features and bugs
+
+Please file feature requests and bugs at the [issue tracker][tracker].
+
+[tracker]: https://github.com/ProtoCatTeam/js_util/issues
« no previous file with comments | « packages/js_util/LICENSE ('k') | packages/js_util/dist/js_util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698