p-hatan/ mirror

pub repository

mirror.p-hatan.ir

observable

0.20.4+1

Support for marking objects as observable

This package is discontinued upstream.

Download archive

Readme

Build Status

Support for detecting and being notified when an object is mutated.

An observable is a way to be notified of a continuous stream of events over time.

Some suggested uses for this library:

  • Observe objects for changes, and log when a change occurs
  • Optimize for observable collections in your own APIs and libraries instead of diffing
  • Implement simple data-binding by listening to streams

You may want to look at the former TC39 proposal Observe.observe, which was deprecated.

Usage

There are two general ways to detect changes:

  • Listen to Observable.changes and be notified when an object changes
  • Use Differ.diff to determine changes between two objects

Examples

Operations on Lists:

import 'package:observable/observable.dart';

void main() {
  var changes;

  ObservableList<String> list = new ObservableList<String>.from(['a', 'b', 'c']);
  StreamSubscription sub = list.listChanges.listen((c) => changes = c);

  ListChangeRecord _delta(
    int index, {
    List removed: const [],
    int addedCount: 0,
  }) {
    return new ListChangeRecord(
      list,
      index,
      removed: removed,
      addedCount: addedCount,
    );
  }

  list.insertAll(1, ['y', 'z']); // changes == [_delta(1, addedCount: 2)]
}

Diffing two maps:

import 'package:observable/observable.dart';

void main() {
  final map1 = {
    'key-a': 'value-a',
    'key-b': 'value-b-old',
  };

  final map2 = {
    'key-a': 'value-a',
    'key-b': 'value-b-new',
  };

  var diffResult = diff(map1,
      map2); // [ new MapChangeRecord('key-b', 'value-b-old', 'value-b-new')]
}

Diffing two sets:

import 'package:observable/observable.dart';

void main() {
  diff(
    new Set<String>.from(['a', 'b']),
    new Set<String>.from(['a']),
  ); // [ new SetChangeRecord.remove('b') ]
}
Changelog

0.20.4+1

  • Support the latest release of pkg/quiver.

0.20.4

  • Bug fix: Additional fix around ObservableList.listChanges

0.20.3

  • Bug fix: Avoid emitting an empty list via ObservableList.listChanges

0.20.2

  • Bug fix: Avoid emitting a no-op MapChangeRecord
  • Bug fix: Restore ObservableList.discardListChanges functionality

0.20.1

  • Add Observable<List|Set|Map>.unmodifiable for immutable collections
  • Add Observable<List|Set|Map>.EMPTY for empty immutable collections
    • This can be used as an optimization for libraries that always need to return an observable collection, but don't want to allocate a new instance to represent an empty immutable.

0.20.0

  • Add ObservableSet, SetChangeRecord, and SetDiffer

0.19.0

  • Refactor and deprecate ObservableMap-specific API
    • ObservableMap no longer emits #keys and #values change records
    • ObservableMap.spy is deprecated, becomes .delegate instead
  • Potentially breaking: ObservableMap may no longer be extended

It is also considered deprecated to be notified of length changes.

0.18.1

  • Bug fix: Do not throw when Observable<T>.notifyChange is used

0.18.0

  • Refactor and deprecate ObservableList-specific API
    • ObservableList.applyChangeRecords
    • ObservableList.calculateChangeRecords
    • ObservableList.withLength
    • ObservableList.deliverListChanges
    • ObservableList.discardListChanges
    • ObservableList.hasListChanges
    • ObservableList.listChanges
    • ObservableList.notifyListChange
  • Potentially breaking: ObservableList may no longer be extended

It is also considered deprecated to be notified of length, isEmpty and isNotEmpty PropertyChangeRecords on ObservableList - in a future release ObservableList.changes will be Stream<List<ListChangeRecord>>.

0.17.0+1

  • Revert PropertyChangeMixin, which does not work in dart2js

0.17.0

This is a larger change with a goal of no runtime changes for current customers, but in the future Observable will become a very lightweight interface, i.e.:

abstract class Observable<C extends ChangeRecord> {
  Stream<List<C>> get changes;
}
  • Started deprecating the wide Observable interface
    • ChangeNotifier should be used as a base class for these methods:
      • Observable.observed
      • Observable.unobserved
      • Observable.hasObservers
      • Observable.deliverChanges
      • Observable.notifyChange
    • PropertyChangeNotifier should be used for these methods:
      • Observable.notifyPropertyChange
    • Temporarily, Observable uses ChangeNotifier
      • Existing users of anything but implements Observable should move to implementing or extending ChangeNotifier. In a future release Observable will reduce API surface down to an abstract Stream<List<C>> get changes.
  • Added the ChangeNotifier and PropertyChangeNotifier classes
    • Can be used to implement Observable in a generic manner
  • Observable is now Observable<C extends ChangeRecord>
    • When passing a generic type C, notifyPropertyChange is illegal

0.16.0

  • Refactored MapChangeRecord
    • Added equality and hashCode checks
    • Added MapChangeRecord.apply to apply a change record
  • Added MapDiffer, which implements Differ for a Map

0.15.0+2

  • Fix a bug in ListDiffer that caused a RangeError

0.15.0+1

  • Fix analysis errors caused via missing /*<E>*/ syntax in 0.15.0

0.15.0

  • Added the Differ interface, as well as EqualityDiffer
  • Refactored list diffing into a ListDiffer
  • Added concept of ChangeRecord.ANY and ChangeRecord.NONE
    • Low-GC ways to expression "something/nothing" changed
  • Refactored ListChangeRecord
    • Added named constructors for common use cases
    • Added equality and hashCode checks
    • Added ListChangeRecord.apply to apply a change record
  • Added missing @override annotations to satisfy annotate_overrides

0.14.0+1

  • Add a missing dependency on pkg/meta.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add observable
pubspec.yaml
name: observable
version: 0.20.4+1
author: Dart Team <misc@dartlang.org>
description: Support for marking objects as observable
homepage: https://github.com/dart-lang/observable
environment:
  sdk: '>=1.22.0 <2.0.0'
dependencies:
  collection: '^1.11.0'
  meta: '^1.0.4'
  quiver: '>=0.24.0 <0.26.0'
dev_dependencies:
  test: '^0.12.17'

Version history

VersionPublishedArchiveSHA-256
0.1.02014-06-06T16:41:32.001090ZDownloadd6fdf1e65de6103941a7377d4d268d4147c47850536b70850be8686a4bb8282f
0.1.12014-06-06T17:10:06.910100ZDownload8aa5feb72be0bfdb8d344ddd2da3dd13a2630da5e71dc40c8e30ba020fbeb59b
0.1.22014-06-06T18:12:36.721340ZDownload79d8074f5f771078c368508b836584dbce4a2d5b74cb80800d4cb03cc14950c2
0.1.32014-06-08T15:07:06.198290ZDownload142ddf0b61a4b653bda1a28a22ed2a57bfa21620f21daacee603a7087e875ba5
0.1.42014-06-08T15:08:37.263640ZDownloadac8da8a48ed40a2c169ed49135b277897a5c710f101bf88884f6477f0f144080
0.1.52014-06-11T12:09:08.919140ZDownloadaed2d42592befd39e1ca321631118d99538dff6bbfcc8fab70bcb3fac6df37d2
0.1.62014-06-11T13:46:07.823640ZDownload98674349a58d899c16c21927b0b625c7299e9b35872150a92f8727a74a0200c7
0.14.02016-09-23T20:48:35.289ZDownloadc5fc18c79e862c880c604568ac949e427d82214098f250d890ec824461940996
0.14.0+12016-09-26T17:05:37.029ZDownload549d63f721775224e229510760304766448b02c62c48f248192ea3a3c36aed9b
0.15.0+12016-11-17T01:37:36.985ZDownloadd8427a2b87da22a818d2b4e1b37c7f45775e26e0ccfbd63884c1d85a4a945111
0.16.02016-11-17T18:32:04.548ZDownloadb8abdac0b1ac8b296a961f6ae24247ec15a30755b734b68f67d1bf8394e87ff7
0.17.02016-11-17T23:17:29.180ZDownload01328f5b4c877837d64440daf0e8c343a122948689d195708953d4dad0cf013b
0.17.0+12016-11-21T18:59:50.788ZDownload8a6c6e21e1a5fc032fc49cfc28c5c3574962dbed3252d8570a5b1e4174c73025
0.18.02016-11-22T04:50:21.072ZDownloadbe648ac636727693806487e7e07a640665336fd2dff97582c5fcbd9e7ed70876
0.18.12016-11-22T20:16:21.692ZDownload44e76715dee5848404d4c1d6b0a39333f6f791d8c7c48e2bb4abc2204995dfbd
0.19.02016-11-23T01:31:07.467ZDownload371d4356dc92f71a004c71301fecb5237f43dff5e1f789ff79edc844078c0cde
0.20.12016-11-29T03:07:45.483ZDownloadba572ba1f5f11072e7109490ce416cb1338528c54a8561cadf154fe2d630397e
0.20.22016-12-20T07:22:32.443ZDownloadb9b4f7107089afb58f73346ddf9da4e64e56a02e62b729694c0129e484cc9d06
0.20.42017-02-25T04:21:45.913ZDownloadd6308bf35fc8803fed7e026fc991cf2ad4e02be63055a15eac9a2c51b3761d63
0.20.4+12017-04-04T20:02:29.019802ZDownload5382b3f529e69b44888baaa595eca60127290b4d26c223fd996a2d6561b71933
0.20.4+22017-12-27T18:49:28.130687ZDownload375870ad899a83138014f715c4031785445bcc0860b010ab08523e3ceb37b61e
0.20.4+32018-01-09T01:26:36.225295ZDownload898df861aa2c37614f81e00d5da4e6e50496a925f16a81a7e49b1ed5967df464
0.21.02018-02-12T18:09:51.151116ZDownloadebb9ff4bd8b957ef2bc102e1e604b04cab48b2ca9fcf5873854feae1c87d8a99
0.21.12018-03-01T02:04:09.492545ZDownload60c73ae870a0f001a23ce12678d815f3b932032763413d1bb15bd514af169301
0.21.22018-03-07T23:28:47.382783ZDownloadad3b0443325a0f10ca328555bd68d287f27d06d1a81b1abb065ccf413353957e
0.21.32018-03-13T16:59:28.153540ZDownloadf4e963b40cd0b460122a958ff77ccf97597a85e39cfab0b7303d9437a5c8f6b0
0.22.02018-03-19T17:07:57.288351ZDownloada7722c1d562039d433cb6b8cd257d6bc784d26ce044725409065d16136dc124a
0.22.12018-03-23T23:29:35.934828ZDownload2a88d6c6182bb1cc3d95841ff40a6f2bd54e527f76b21693d32680ea127f5f9f
0.22.1+12018-05-03T16:19:13.923304ZDownload631b89955023d9dd0a456cd21de780259bc759bbe98277fe7a1ebc6b6bb41e6f
0.22.1+22018-05-18T22:13:21.263251ZDownloadcb24c2888248a842710be263b9a981eba24563c6fd8351c08cc3b52b5ac765a7
0.22.1+32018-05-25T17:11:35.455328ZDownloaddda14d0c17ef7846f748aca2c8cdf388f326cc1b66bd963779d0f20cce267692
0.22.1+42018-07-23T18:41:54.734062ZDownloade45aeef60f47c2696b36718b383aad7cef9a7b252dcb6d16df6261906e96b957
0.22.1+52018-12-10T22:17:15.043501ZDownloada99d958c8483e369da3ab6832148364dc73fc22f6ee6c9792cbc8ecae7964e27
0.22.22019-02-05T22:26:59.772301ZDownloadbb74db48ca45dc26ae0e3f15334e2bd844ceacc23a31e9c18045df311833129f
0.23.02021-03-23T17:30:12.296140ZDownload72aeca9b76959826ca380bfe2517bc21a6a25d56f41ab620f1421728ffa5e564
0.24.02021-12-01T23:27:45.159724ZDownload6be2c1236cd4130a0e752895b0d3dee6d438d4c0b6775b8fe5808cf981aa9a70

Dependencies

collection "^1.11.0"

meta "^1.0.4"

quiver "\u003e=0.24.0 \u003c0.26.0"