lawndart 0.9.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 55

Lawndart

A unified, asynchronous, easy-to-use library for offline-enabled browser-based web apps. Kinda sorta a port of Lawnchair to Dart, but with Futures and Streams.

Lawndart uses Futures to provide an asynchronous, yet consistent, interface to local storage, indexed db, and websql. This library is designed for simple key-value usage, and is not designed for complex transactional queries. This library prefers simplicity and uniformity over expressiveness.

You can use this library to help deal with the wide array of client-side storage options. You should be able to write your code against the Lawndart interface and have it work across browsers that support at least one of the following: local storage, indexed db, and websql.

Example

  // Picks the best store available.
  var db = await Store.open("simple-run-through", 'test');
  await db.open();
  await db.nuke();
  await db.save("world", "hello");
  await db.save("is fun", "dart");
  var value = await db.getByKey("hello");
  querySelector('#text').text = value;
  

See the example/ directory for more sample code.

Choosing the best storage option

This is now made easy for you. Simply create a new instance of Store:

  var store = await Store.open('dbName', 'storeName');
  

The factory constructor will try IndexedDB, then WebSQL, and then finally local storage. Of course, you can perform your own logic to choose which option works for you.

API

Future Store.open() Opens the database and makes it available for reading and writing.

Future nuke() Wipes the database clean. All records are deleted.

Future save(value, key) Stores a value accessible by a key.

Future getByKey(key) Retrieves a value, given a key.

Stream keys() Returns all keys.

Stream all() Returns all values.

Future batch(map) Stores all values and their keys.

Stream getByKeys(keys) Returns all values, given keys.

Future exists(key) Returns true if the key exists, or false.

Future removeByKey(key) Removes the value for the key.

Future removeByKeys(keys) Removes all values for the keys.

Usage

Most methods return a Future, like open and save. Methods that would return many things, like all, return a Stream.

Supported storage mechanisms

  • Indexed DB - Great choice for modern browsers
  • WebSQL - Well supported in mobile WebKit browsers, not in Firefox
  • Local Storage - Only 5MB, slow, more-or-less universal
  • Memory - Good for testing

You can consult Can I Use? for a breakdown of browser support for the various storage technologies.

Install

Lawndart is a pub package. To install it, and link it into your app, add lawndart to your pubspec.yaml. For example:

name: your_cool_app
dependencies:
  lawndart: any
  

If you use Dart Editor, select your project from the Files view, then go to Tools, and run Pub Install.

If you use the command line, ensure the Dart SDK is on your path, and the run: pub install

Support

Lawndart is hosted at https://github.com/sethladd/lawndart

You can file issues at https://github.com/sethladd/lawndart/issues

API docs at http://sethladd.github.com/lawndart/

This library is open source, pull requests welcome!

Authors

  • Seth Ladd (sethladd@gmail.com)

License

Copyright 2015 Google

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

0.9.0

  • BREAKING CHANGE: creating and opening a store are the same operation open() is a static method on Store
  • Using the new async/await/async*/yield features.
  • BREAKING CHANGE: No more generics. Stores are simply String => String stores now.

0.6.5

  • Reduce size of WebSQL down to 4MB, avoids permission check.

0.6.2

  • Update to SDK version 0.8.5
  • Remove old web_ui example

0.6.1

  • Fix bug with chained opens of multiple stores, followed by a read.

0.6.0

  • No more explicit version for indexed, it's automatically handled.
  • Better support for multiple store names per IndexedDB.
    • Thanks to https://github.com/davidB

0.5.0

  • Added factory constructor to automatically choose the best store.
  • Updated to hop standalone.

0.4.2

  • Added IndexedDbStore.supported
  • Added WebSqlStore.supported
  • Renamed all the adapters to stores
  • The TODO sample app now works in Safari, Chrome, and Firefox

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  lawndart: "^0.9.0"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:lawndart/lawndart.dart';
        
Version Uploaded Documentation Archive
0.9.0 Mar 31, 2015 Go to the documentation of lawndart 0.9.0 Download lawndart 0.9.0 archive
0.6.5 Jan 18, 2014 Go to the documentation of lawndart 0.6.5 Download lawndart 0.6.5 archive
0.6.4 Oct 24, 2013 Go to the documentation of lawndart 0.6.4 Download lawndart 0.6.4 archive
0.6.3 Oct 24, 2013 Go to the documentation of lawndart 0.6.3 Download lawndart 0.6.3 archive
0.6.2 Oct 24, 2013 Go to the documentation of lawndart 0.6.2 Download lawndart 0.6.2 archive
0.6.1 Jun 28, 2013 Go to the documentation of lawndart 0.6.1 Download lawndart 0.6.1 archive
0.6.0 Jun 27, 2013 Go to the documentation of lawndart 0.6.0 Download lawndart 0.6.0 archive
0.5.0 May 24, 2013 Go to the documentation of lawndart 0.5.0 Download lawndart 0.5.0 archive
0.4.3 Apr 18, 2013 Go to the documentation of lawndart 0.4.3 Download lawndart 0.4.3 archive
0.4.2 Mar 21, 2013 Go to the documentation of lawndart 0.4.2 Download lawndart 0.4.2 archive

All 18 versions...

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Jan 21, 2018
  • Dart: 2.0.0-dev.15.0
  • pana: 0.10.0

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
77 / 100
Health:
Code health derived from static analysis. [more]
56 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0 / 100
Overall score:
Weighted score of the above. [more]
55

Platforms

Detected platforms: web

Primary library: package:lawndart/lawndart.dart.

Suggestions

  • Fix lib/src/_map_store.dart.

    Strong-mode analysis of lib/src/_map_store.dart failed with the following error:

    line: 38 col: 3
    Invalid override. The type of '_MapStore.save' ('(String, String) → Future<dynamic>') isn't a subtype of 'Store.save' ('(String, String) → Future<String>').

  • Fix lib/src/local_storage_store.dart.

    Strong-mode analysis of lib/src/local_storage_store.dart failed with the following error:

    line: 33 col: 3
    Invalid override. The type of 'LocalStorageStore._generateMap' ('() → Map<dynamic, dynamic>') isn't a subtype of '_MapStore._generateMap' ('() → Map<String, String>').

  • Fix further 2 Dart files.

    Similar analysis of the following files failed:

    • lib/src/websql_store.dart
    • lib/src/indexeddb_store.dart
  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 3 error(s) and 0 warning(s).

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use lawndart.dart.

Dependencies

Package Constraint Resolved Available
Dev dependencies
browser any
unittest any