Coder Social home page Coder Social logo

Comments (12)

rrousselGit avatar rrousselGit commented on August 21, 2024 4

I'll go for StateNotifierProvider.autoDispose.family(...).
This avoids a name clash with variables named provider, and is more natural for people migrating from provider

It'll then be accompanied by:

  • .retry, as per #42
  • (maybe) .restorable, for state restoration:
    final model = StateNotifierProvider.future.restorable(
      (ref) async {
        final json = await ref.restore();
        final initialState = json == null ? null : MyModel.fromJson(json);
        return MyNotifier(initialState: initialState);
      },
      name: 'model',
      serialize: (state) => state.toJson(),
    );

from riverpod.

davidmartos96 avatar davidmartos96 commented on August 21, 2024 2

I agree with the proposal.
I think that having too many different class names can be confusing for people trying out the package.
I also agree that keeping some of the providers with the original name can be helpful for people used to the well known Providers in the provider package.

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024 1

I've just realised that we can't implement Provider.changeNotifier(...) as ChangeNotifier is Flutter-only, and extensions do not allow adding static members.

So this reinforces the idea of keeping StateNotifierProvider & co, and apply this logic only to AutoDispose, Family and a potential Retry.

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024 1

Another alternative is to do like @smiLLe suggested and go for final foo = provider.autoDispose(...) instead of final foo = Provider.autoDispose(...).

This will allow using extensions to add custom members. And to begin with, we don't care about const constructors, so this using a function over a constructor doesn't matter.

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024 1

Logging in implemented directly on ProviderScope

ProviderScope(
  observers: [
    LoggerObserver(),
  ],
  child: MyApp(),
);

class LoggerObserver extends ProviderStateOwnerObserver {
  ...
}

Although maybe we could have an "onChange" on providers individually

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024 1

I do. Finding Recoil made me rename Family. Originally the pattern was called "ParametrizedProvider", which just sounds bad

Anyway, we'll see later. I'll focus on retry/restorable. There's a bunch of work to do on for the provider code-generator

from riverpod.

smiLLe avatar smiLLe commented on August 21, 2024

For my current project I started to do

final myProvider = createProvider.stateNotifier.family<T, Fam>((r, f) => .. );

by just using callable classes :)

from riverpod.

smiLLe avatar smiLLe commented on August 21, 2024

Personally i would prefer Retry over anything else :P

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024

I like how composable the modifier idea is. It allows implementing commonly wanted features almost without doing anything.

Do you have any modifiers in mind that I haven't mentioned yet?

Currently we'd have:

  • retry
  • autoDispose
  • family
  • restorable

What other big feature would we want? 🤔

from riverpod.

davidmartos96 avatar davidmartos96 commented on August 21, 2024

@rrousselGit Some kind of logging mechanism? Not sure if that is possible, just sharing the idea 😅

from riverpod.

smiLLe avatar smiLLe commented on August 21, 2024

What other big feature would we want? 🤔

Do you know recoil js? It is very similar to riverpod :) Maybe we can take some inspiration from them.
But right now, all i am missing is Retry and i like the idea of .restorable

from riverpod.

AlexHartford avatar AlexHartford commented on August 21, 2024

I would agree that the change in name convention makes a great deal of sense here.

from riverpod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.