Angular-Meteor using $state outside of the constructor - angular-meteor

I'm new to Angular-Meteor. I noticed I could use $state in the constructor method (passed as a param), but it won't really work in methods outside of the constructor. What's the correct way of using it (if) outside the constructor method?

My technique is to set it equal to a similarly named property on this.
As an example:
this.$state = $state;
Then to access it in the other methods, you can via this.$state throughout your class.

Related

What is difference between Laravel `app` method and `new` keyword?

I found that some developer use app(SomeService::class); while other use new SomeService(); in Laravel? Is there any difference between them?
Yes, the main difference is the ServiceContainer.
If you instantiate using app(YourService::class), the ServiceContainer will use reflection to inject in the class constructor the dependecies required.
So you don't have to explicit use all the dependencies needed.
It's well explained here.
Please check https://laravel.com/docs/5.7/providers.
Briefly speaking if you want to customize the class which you will use in runtime you can change it in provider (make it singleton or pass some arguments) and get in runtime via $app (if you have no opportunity to use DI). but when you making object vie new its only creates an instance.
Imagine that we have class A which receive 2 config parameters in construction.
So you need everywhere call new A($param1,$param2) . but using providers u can use DI to get instance of class A with already passed parameters or $app if u have no opportunity to use DI

What does the `free` method from TProcess do?

What does the free method do in TProcess. It's used in several examples I found on the net but there's nothing in the reference about it? So far I used it and everything works fine. Can I continue to use it or should I use a different method?
It is the Free method defined in TObject, at the very root of the class hierarchy. This method does the same thing in every single class, there is nothing special with TProcess in this regard.
It is documented:
Free will check the Self pointer and calls Destroy if it is different from Nil. This is a safer method than calling Destroy directly.

Manually calling controller method with parameter and still have method injection

How can I call a controller method manually specifying some input parameters yet still have method injection work for the parameters not specified (example below).
routes.php
$myController->index($id);
controllers/MyControllerOne.php
class MyControllerOne
{
public function index($id, MyRequest $request)
{
}
}
extra information
The reason I need this is because I have special information in my routes that determines which controller should be executed such as /myroute/{data}/{id}. It's a bit unorthodox but it's a necessary evil given the scope of our system.
Once I resolve within my routes which controller needs to be called I then want to call the method on that controller. $controllerInstance->index($id).
If it's only for Request, I think you could manually pass this $this->app->make('Request'), like so
$controllerIntance->index($id, $this->app->make('Request'))
Note that you actually don't have to inject Request, since you might as well use App::make inside of your controller. But I'm not sure how good this decision is in case of testability and coupling.
For more info:
This function resolves 'Request' out of the container, that is instantiates or returns an existing instance (depending of the type of service provider).
Using make is described here http://laravel.com/docs/5.0/container (see "Resolving"). I also found this answer helpful, to understanding how the container works https://stackoverflow.com/a/25798288/1627227

How do automatically generated instance variables work in NSManagedObjects?

Xcode 4.5 and later auto-synthesizes properties, making an instance variable with the underscore prepended on the property name. But how does this work in an NSManagedObject? They want you to use KVC primitive methods in your custom setters. So what happens if you set an instance variable via the underscore ivar inside the NSManagedObject? Won't that screw things up since it would bypass the KVC methods? Or is it safely doing this behind the scenes?
If you access the underscore instance variable directly, you are bypassing the work that NSManagedObject does for you. You should use the get and set accessor methods that NSManagedObject auto-generates for your attributes.
Apple's documentation states
When you access or modify properties of a managed object, you should
use these [accessor] methods directly.
You can implement your own accessor methods if required, but in that case, you have to do additional work beyond changing the value of the instance variable:
You must ensure that you invoke the relevant access and change
notification methods (willAccessValueForKey:, didAccessValueForKey:,
willChangeValueForKey:, didChangeValueForKey:,
willChangeValueForKey:withSetMutation:usingObjects:, and
didChangeValueForKey:withSetMutation:usingObjects:).
This should illustrate that you can't get the correct behavior simply by modifying the instance variable directly.
Note that unlike ordinary properties, NSManagedObject properties are not synthesized at compile time (hence the use of #dynamic for the implementation). Since compile-time synthesis isn't used, there are no synthesized instance variables available for you to set.
Instead, instances of NSManagedObject have a private internal instance of something similar to an NSMutableDictionary to store their state. The dynamically generated property accessors are wrappers for calls to KVC-like methods that access the private storage.

delegate method call

I want to know simply what is the benefit of adding methods using += in delegates..
If you assigned a method to a delegate using =, you would replace any other methods that have already been assigned to that delegate. By using +=, you are adding a new method without removing any existing methods already assigned.

Resources