Reactive-Extensions/rx.angular.js

New methods

xgrommx opened this issue · 2 comments

Hello @mattpodwysocki. What about if I'll implement couple operators like a assignProperty and assignProperties? They should be use so:

obs.$assignProperty(scope or controller, 'property');
obs.$assignProperties(scope or controller, ['property1', 'property2']);

+1

I was just about to implement something like this myself. Just to make sure I understand, is this supposed to be a shortcut for

someObservable.safeApply($scope, function(value) {
    this.prop = value; // when using controllerAs
    // or
    $scope.prop = value;
}).subscribe();

Because that's what I'm looking for.

Wouldn't the $assignProperty operator always need a scope as the first argument so it can delegate to safeApply internally? Even when setting a controller property & using the controllerAs syntax, I think you still have to invoke a $apply() on a Scope instance to get Angular to notice the change.

@mattpodwysocki is this something you'd be interested in accepting?

Looks like this already exists as .digest(), but it's not documented.

// assign someObservable's values to $scope.myProperty, then run a digest if necessary.
someObservable
    .digest($scope, 'myProperty')
    .subscribe();

// assign someObservable's values to a controller property `myProperty`, then run a digest if necessary.
someObservable
    .digest($scope, 'ctrl.myProperty')
    .subscribe();