GithubHelp home page GithubHelp logo

Comments (6)

pavanpodila avatar pavanpodila commented on May 19, 2024 1

Wow this is beautiful. Love it. I definitely have to dig deeper into source_gen and understand its capabilities. From the looks, it is very promising and opens up a world of possibilities with some meta-programming wizardry.

Thanks for sharing a detailed example 💯

from mobx.dart.

pavanpodila avatar pavanpodila commented on May 19, 2024

Our API is already providing it: observable(10). For a factory the identifier would just become capitalized. Still not clear if a function or a factory-constructor is better. Since I am jaded by using MobX JavaScript, I am just leaning towards a function.

How about we provide both for now and see what sticks ??

from mobx.dart.

katis avatar katis commented on May 19, 2024

We can just keep the builder function, I don't see the point in providing two ways to do things.
Maybe in the future this whole point will be moot if we can create a code generator that does the same kind of magic as MobxJS annnotations. Then the use of builders would probably be rare any way.

from mobx.dart.

pavanpodila avatar pavanpodila commented on May 19, 2024

Let's go the Dart way with factories. Although the API is different in JS, I think we should take the Dart convention.

from mobx.dart.

pavanpodila avatar pavanpodila commented on May 19, 2024

We can just keep the builder function, I don't see the point in providing two ways to do things.
Maybe in the future this whole point will be moot if we can create a code generator that does the same kind of magic as MobxJS annnotations. Then the use of builders would probably be rare any way.

I am still curious how source_gen would help

from mobx.dart.

katis avatar katis commented on May 19, 2024

@pavanpodila sorry, missed your messages.

I think it should be possible to use source_gen to have code like this:

part 'view_model.g.dart';

abstract class ViewModel {
  factory ViewModel() = _$ViewModel;

  @observable
  int counter;

  @action
  void increment() {
    counter++;
  }
}

generate view_model.g.dart like this:

class _$ViewModel extends ViewModel {
  _$ViewModel() {
    _$increment = action(super.increment, name: 'ViewModel.increment');
  }
  
  final _$counter = observable(0); // not sure how to handle initial value yet
  int get counter => _$counter.value;
  set counter(int value) => _$counter.value = value;
  
  Action _$increment;
  @override
  void increment() {
    _$increment();
  }
}

Then you could easily use ViewModel in reactive situations:

final vm = ViewModel();
autorun(() {
  print(vm.counter);
});
vm.increment();
vm.increment();

built_value does this kind of magic to create immutable values classes.

from mobx.dart.

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.