paisley 0.1.4

paisley #

Prince - Purple Rain


SPA engine that sends HTML to clients and handles events via WebSocket. Ideal for smaller apps, built very small teams (like, 1 person).

Named after the 🐐, Prince Rogers Nelson's, Paisley Park recording studio.

Fairly experimental.

Rationale #

This was partially made just for fun, but also to shrink development for solo apps. No need to maintain both an Angel server and a React/Angular frontend, etc. Also, there's no need to use a module bundler.

State #

You need to roll-your-own state management, especially to persist state after a reconnect.

window.localStorage is sent to Component.afterCreate. Use it accordingly...

Also, Paisley is smart enough to know when a reconnect occurs, and will not reset the whole page. This way, users can have as seamless an experience as is possible.

Gracefully handling disconnects #

Paisley handles disconnects by reconnecting (using a truncated exponential backoff to not spam your server).

Use Component.afterCreate to continue running from a previous state.

In addition, when Paisley disconnects, it adds the paisley-disconnected CSS class to document.body, so you can potentially show some conditional content.

Installation #

In your pubspec.yaml:

  paisley: ^0.0.0

0.1.4 #

  • Register window.paisley and support sending notifications to the JS client.

0.1.3 #

  • Fix handling of empty HTML pushes, etc.

0.1.2 #

  • Fix LocalStorage.setItem.

0.1.1+3 #

  • Remove a stray print statement...

0.1.1+2 #

  • beforeRoot defaults to '' in PaisleyApp.

0.1.1+1 #

  • Correct typo in README.

0.1.1 #

  • Add isReconnect flag to init.
  • Reset backoff after connection success.

0.1.0 #

  • Fixed some bugs. Mostly to appease pana.
  • Perfected reconnection/onconnect code.


import 'dart:async';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:logging/logging.dart';
import 'package:paisley/paisley.dart';
import 'package:paisley/server.dart';

main() async {
  var app = Angel();
  var http = AngelHttp(app);
  app.logger = Logger('paisley')..onRecord.listen(print);

  /// Render a default page when we hit the index.
  app.get('/', paisleySsr((req, res) {
    return PaisleyApp(

      // Add some styles, etc. to handle disconnects gracefully
      // by modifying the UI.
      head: '''
        body:not(.paisley-disconnected) #disconnected {
          display: none;

        #disconnected {
          color: red;
          font-weight: bold;
      beforeRoot: '''
      <i id="disconnected">Disconnected. Trying to reconnect...</i>

  /// Serve WebSockets for Paisley.
  app.get('/paisley', paisley((req, res) => Hello(req)));

  // 404 otherwise.
  app.fallback((req, res) => throw AngelHttpException.notFound());

  await http.startServer('', 3000);
  print('Listening at ${http.uri}');

class Hello extends Component {
  final RequestContext req;
  var _clicks = 0;


  void afterCreate([PaisleyServer server, Map<String, String> localStorage]) {
    if (server != null) {
      server.eval('"Hello, Paisley!!!")');

      // Restore past click amount, if any.
      if (localStorage.containsKey('clicks'))
        _clicks = int.parse(localStorage['clicks']);

      listen('click', (_) async {
        server.pushHtml('button', 'Clicked ${++_clicks} time(s)!');
        await server.localStorage.setItem('clicks', _clicks);

  FutureOr<String> render() {
    return '''
    <h1>Session ID: ${}</h1>
    <button onclick="fire('click')">Click me!</button>

Use this package as a library

1. Depend on it

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

  paisley: ^0.1.4

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:paisley/paisley.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19


Detected platforms: Flutter, other

Primary library: package:paisley/paisley.dart with components: io, isolate.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (stream_channel).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
angel_framework ^2.0.0-rc.0 2.0.4
angel_serialize ^2.0.0 2.2.3+2
html_builder ^1.0.0 1.0.5
http_parser ^3.0.0 3.1.3
json_god ^2.0.0-beta 2.0.0-beta+3
json_rpc_2 ^2.0.0 2.1.0
stream_channel ^1.0.0 1.7.0 2.0.0
web_socket_channel ^1.0.0 1.0.14
Transitive dependencies
angel_container 1.0.4
angel_http_exception 1.1.0
angel_model 1.0.3
angel_route 3.0.6
async 2.3.0
charcode 1.1.2
code_buffer 1.0.1
collection 1.14.11
combinator 1.1.0
convert 2.1.1
crypto 2.0.6
dart2_constant 1.0.2+dart2
file 5.0.8+1
http2 1.0.0
http_server 0.9.8+3
intl 0.15.8
matcher 0.12.5
merge_map 1.0.2
meta 1.1.7
mime 0.9.6+3
mock_request 1.0.6
path 1.6.2
quiver 2.0.3
quiver_hashcode 2.0.0
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
tuple 1.0.2
typed_data 1.1.6
uuid 2.0.2
Dev dependencies
angel_serialize_generator ^2.0.0
build_runner ^1.0.0
logging ^0.11.0 0.11.3+2
pedantic ^1.0.0 1.8.0+1
test ^1.0.0