GithubHelp home page GithubHelp logo

mobxjs / mobx-angularjs Goto Github PK

View Code? Open in Web Editor NEW
51.0 51.0 3.0 316 KB

MobX connector to AngularJS

License: MIT License

JavaScript 39.59% HTML 13.81% TypeScript 46.60%
angularjs mobx mobx-connector ng-mobx

mobx-angularjs's People

Contributors

adamkleingit avatar kuitos avatar nickbreaton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mobx-angularjs's Issues

distribution bundle size

It seems the ng-mobx.js in dist is very huge since we use webpack to bundle both angular and mobx. However, package json describes both angular and mobx are peer dependencies. Hence the bundling part seems incorrect.

Unmet Peer Dependency

When using latest version of mobx - currently 3.1.0, we are getting below error from yarn install log:

warning "[email protected]" has incorrect peer dependency "mobx@^2.6".

Does that mean ng-mobx is compatible only with mobx 2.x?

mobx-autorun link error

line 1 of mobx-autorun link is
var _a = $scope.$$watchers, $$watchers = _a === void 0 ? [] : _a;
$scope.$$watchers is null for me when using angularjs 1.7.
this should be changed to $$watchers = typeof _a !== 'array' ? [] : _a;

Best practices?

I'm looking at using this excellent looking library to retrofit a large AngularJS application where nearly everything is currently in the scope.

While I can follow what the the example is doing and why this directive is necessary here, I'm not sure what the best way to retrofit our code base is. For example, what should we do with existing code that uses "ng-click" or "ng-model" or anything that triggers a digest cycle? It seems to me that if we just referenced our mobx store through our scope and didn't change anything else, this directive wouldn't be necessary.

So...is the recommendation to use "onclick" instead of "ng-click" when triggering a mobx action, for example?

Thanks!

Any reason to use library instead of this code snippet?

This will run all the watchers inside autorun and track all the dependencies, without using internal angular variables

mobx.autorunAsync('$rootScope#$digst', () => {
    $rootScope.$digest();
}, 2);

Please let me know if I missed anything

Error is $scope.$$watchers is null

https://github.com/500tech/ng-mobx/blob/master/lib/ng-mobx.js#L20

This happens if you use mobx-autorun and ng-if on the same element.

<div ng-if="!$ctrl.sessionStore.isLoggedIn()" mobx-autorun>
 // login
</div>
<div ng-if="$ctrl.sessionStore.isLoggedIn()" mobx-autorun>
  // logout
</div>

Moving mobx-autorun to a wrapper fixes the issue, but this is not always ideal.

<div mobx-autorun>
  <div ng-if="!$ctrl.sessionStore.isLoggedIn()">
   // login
  </div>
  <div ng-if="$ctrl.sessionStore.isLoggedIn()">
    // logout
  </div>
</div>

$apply already in progress

Hi,

I am currently getting the following error:

 [$rootScope:inprog] $apply already in progress
http://errors.angularjs.org/1.5.11/$rootScope/inprog?p0=%24apply

When i apply the directive to an ng-repeat like:

<tr mobx-autorun ng-repeat="employee in $ctrl.employees">
            <td>{{employee.id}}</td>
            <td>{{employee.firstName}}</td>
            <td>{{employee.lastName}}</td>
            <td>{{employee.fullName}}</td>
</tr>

Should the following code:

!$scope.$$phase && $scope.$digest()

not be:

var phase = this.$root.$$phase;
if(phase == '$apply' || phase == '$digest') {

see: https://coderwall.com/p/ngisma/safe-apply-in-angular-js

Where should I place the 'mobx-autorun' for nested components?

Proposal for Maintainer Help and Official Support

Hello @adamkleingit.

This library has proven useful to me in the past few days. I hope to get my company to use it soon in order to ease a transition from AngularJS to React. I appreciate the time you put into it.

I had a few issues and noticed that @kuitos had forked and fixed most of them. It seems that you may not have had the time or desire to keep up with the maintenance of this project to merge them back in, #5, which is totally understandable when you are busy maintaining something like mobxjs/mobx-angular. I, on the other hand, do not have any open source projects to maintain and would love to help out.

If you are up for it, I propose that we make a few changes:

  1. We could possibly move the repo under the mobxjs organization as mobxjs/mobx-angularjs, cc @mweststrate.

  2. Deprecate ng-mobx on npm, and align it with the same naming convention as mobx-angular, publishing under mobx-angularjs, if that is okay with @kuitos.

  3. Align the codebase with the conventions of mobx-angular and incorporate changes made by @kuitos. I have done this here and will gladly submit a PR.

Cheers!

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.