패키지, 저장소 및 앱 카테고리 검색

패키지 상세v6.0.6

observable_ish

관찰 가능한 상태와 이벤트 발신기를 사용하여 우아한 반응형 크로스플랫폼 클라이언트 측 애플리케이션을 작성하세요.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.4천
좋아요
66
Pub 점수
150

패키지 설치

flutter pub add observable_ish

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Observable_ish는 플랫폼 간 관측 가능한 상태와 이벤트 방출을 우아하게 처리할 수 있는 가벼운 반응형 상태 관리 솔루션입니다. Android, iOS, Web, macOS, Windows, Linux에서 크로스플랫폼 개발을 지원하여 반응형 클라이언트 앱을 구축하는 데 이상적입니다. 반응형 패턴을 통해 깔끔하고 선언적인 UI 업데이트를 촉진하며, 부가 코드 없이 상태 동기화를 단순화합니다. 간결함과 성능을 고려해 설계되었으며, 직관적인 API를 사용해 Flutter 프로젝트에 원활하게 통합됩니다.

사용 사례

  • 실시간 데이터 업데이트
  • 폼 상태 관리
  • 크로스 플랫폼 반응형 UI
  • 이벤트 기반 애플리케이션 로직
  • 동적 UI 컴포넌트

주요 기능

  • 반응형 관측 가능한 상태
  • 이벤트 에미터 패턴
  • 최소한의 보일러플레이트
  • 크로스 플랫폼 지원
  • Flutter와의 간편한 통합
  • 경량 설계

적합한 대상

  • 간단한 반응형 상태 관리를 찾는 개발자
  • 실시간 UI 업데이트가 필요한 프로젝트
  • 크로스 플랫폼 플러터 앱
  • 상태 처리를 위한 최소 설정을 원하는 팀
  • 자주 UI 상태가 변경되는 애플리케이션

고려 사항

  • 대규모 복잡한 상태 트리에 적합하지 않음
  • 성숙한 대안에 비해 문서화가 제한적
  • 작은 규모에서 중간 규모의 애플리케이션에 적합
  • 디버깅을 위해 추가 도구가 필요할 수 있습니다
  • 인기 있는 상태 관리 패키지보다 커뮤니티 채택률이 낮음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

observable_ish

Write elegant reactive cross-platform client side application using observable states and event emitters.

Provides:

  1. Reactive Values
  2. Reactive Lists
  3. Reactive Sets
  4. Reactive Maps
  5. Event emitter

Philosophy

Observable-ish provides a light-weight non-intrusive reactive framework to build cross-platform UI. It uses Dart's asynchronous Streams to emit and listen to changes.

Various observable types like RxValue, RxList, RxSet and RxMap can be used to update UI automatically on changes. Events can be passed up the widget tree using event Emitter.

Reactive values

RxValue can be used to encapsulate a simple observable value.

Getting and setting value

RxValue exposes field value to get set current value.

main() {
  final rxInts = RxValue<int>(initial: 5);
  int got = rxInts.value; // Gets current value
  rxInts.value = 10;      // Sets current value
}

When a value that is different from the existing value is set, the change is notified through various ways explained in the section.

Listening to changes

It provides few flexible ways to listen to changes:

  1. onChange: Record of changes
  2. values: Stream of new values
  3. listen: Callback function with new value
main() {
  final rxInts = RxValue<int>(initial: 5);
  print(rxInts.value);  // => 5
  rxInts.values.listen((int v) => print(v));  // => 5, 20, 25
  rxInts.value = 20;
  rxInts.value = 25;
}
Binding to a value

Binding an RxValue to a Stream (using method bindStream) or another RxValue (using method bind) changes its value when the source Stream emits or RxValue changes. This is very useful in scenarios where one would like to change a model's value or widget's property when control changes. For example, change a text field's value when a checkbox is toggled.

  textBox.value.bindStream(checkBox.checked.map((bool v) => v?'Female': 'Male'));
Full examples
main() {
  final rxInts = RxValue<int>(initial: 5);
  print(rxInts.value);  // => 5
  rxInts.value = 10;
  rxInts.value = 15;
  rxInts.values.listen((int v) => print(v));  // => 15, 20, 25
  rxInts.value = 20;
  rxInts.value = 25;
}

Composite reactive objects

Observable-ish is designed to be non-intrusive. The philosophy is to separate the model and its reactive cousin into different classes.

class RxUser {
  final name = RxValue<String>();
  final age = RxValue<int>();
}

class User {
  final rx = RxUser();

  User({String name, int age}) {
    this.name = name;
    this.age = age;
  }

  String get name => rx.name.value;
  set name(String value) => rx.name.value = value;

  int get age => rx.age.value;
  set age(int value) => rx.age.value = value;
}

main() {
  final user = User(name: 'Messi', age: 30);
  user.age = 31;
  print(user.age);  // => 31
  print('---------');
  user.age = 32;
  user.rx.age.listen((int v) => print(v));  // => 20, 25
  user.age = 33;
  user.age = 34;
  user.age = 35;
}

Event emitter

Emitters provide a simple interface to emit and listen to events. It is designed to inter-operate with RxValue to provide maximum productivity.

Listening to a event
  1. on: Execute callback on event
  2. listen: Similar to Stream
  3. asStream: Obtain event as Stream
Piping events

pipeTo pipes events to another Emitter.

pipeToValue pipes events to the given RxValue. This could be very helpful in binding events to observable values.

Emitting events

emit, emitOne, emitAll, emitStream and emitRxValue provides various ways to emit events using the Emitter

Reactive Lists

RxList notifies changes (addition, removal, clear, setting) of its elements.

Updating RxList

RxList implements Dart's List.

Besides List's methods, RxList provides convenient methods like addIf and addAllIf to add elements based on a condition. This is very useful in writing UI in Dart DSL (as in Flutter and Nuts).

main() {
  final rxInts = RxList<int>();
  rxInts.onChange.listen((c) => print(c.element)); // => 5
  rxInts.addIf(5 < 10, 5);
  rxInts.addIf(5 > 9, 9);
}

Use assign and assignAll methods to replace existing contents of the list with new content.

Listening for changes

onChange exposes a Stream of record of change of the List.

Reactive Sets

RxSet notifies changes (addition and removal) of its elements.

Updating RxSet

RxSet implements Dart's Set.

Besides Set's methods, RxSet provides convenient methods like addIf and addAllIf to add elements based on a condition. This is very useful in writing UI in Dart DSL (as in Flutter and Nuts).

main() {
  final rxInts = RxSet<int>();
  rxInts.onChange.listen((c) => print(c.element)); // => 5
  rxInts.addIf(5 < 10, 5);
  rxInts.addIf(5 > 9, 9);
}
Listening for changes

onChange exposes a Stream of record of change of the Set.

Binding

bindBool and bindBoolValue allows removing or adding the given element based on the Stream of bools or RxValue of bools.

bindOneByIndexStream and bindOneByIndex allows removing all but the one element from a given Iterable of elements based on index Stream or RxValue.

Reactive Maps

RxMap notifies changes (addition, removal, clear, setting) of its elements.

Updating RxMap

RxMap implements Dart's Map.

Besides Map's methods, RxMap provides convenient methods like addIf and addAllIf to add elements based on a condition. This is very useful in writing UI in Dart DSL (as in Flutter and Nuts).

Listening for changes

onChange exposes a Stream of record of change of the Map.

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.