re_reselect 1.0.0 copy "re_reselect: ^1.0.0" to clipboard
re_reselect: ^1.0.0 copied to clipboard

Re-reselect is a lightweight wrapper around Reselect meant to enhance selectors with deeper memoization and cache management.

example/example.dart

import 'package:re_reselect/rereselect.dart';

class OriginalState {
  final String key;
  final int a;
  final int b;
  final int c;
  final int d;
  OriginalState(this.key, this.a, this.b, this.c, this.d);
}

void main() {
  // First state selector
  final stateSelector1 = (OriginalState state) => state.a + state.b;

  // Second state selector
  final stateSelector2 = (OriginalState state) => state.c + state.d;

  // Computation method
  final combine = (int state1, int state2) => state1 + state2;

  // Create Re-reselect selector from two selector methods and Key as cache key
  final selector = createCachedSelector2(stateSelector1, stateSelector2, combine, (OriginalState state) => state.key);

  // Will execute combine method and print 10
  print(selector(OriginalState('test', 1, 2, 3, 4)));

  // Will NOT execute combine method and print 10 from cache
  print(selector(OriginalState('test', 1, 2, 3, 4)));

  // Will execute combine method and print 10
  print(selector(OriginalState('test2', 1, 2, 3, 4)));

  // Will execute combine method and print 18 (because of params changes)
  print(selector(OriginalState('test2', 1, 10, 3, 4)));

  // Clear cache
  selector.clearCache();
}
2
likes
130
pub points
38%
popularity

Publisher

verified publisherwrike.com

Re-reselect is a lightweight wrapper around Reselect meant to enhance selectors with deeper memoization and cache management.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (LICENSE)

Dependencies

reselect

More

Packages that depend on re_reselect