GetX - How to wrap custom class in Obx - constructor

In GetX, a Widget can be easily wrapped with in the widget tree like this:
Obx (() => Container(//observable stuff in here //)),
However I have an object of a custom type that also returns a widget but cannot be wrapped in Obx. I cannot declare it as a Widget because constructor fields can't be accessed when using Widget as a generic type. I need to access object fields for logic purposes.
For example:
Widget test = MyCustomWidget ({myBool: false, otherStuff: 'bla'});
test.myBool // DOESN'T WORK, CAN'T ACCESS
BUT
MyCustomWidget test = MyCustomWidget ({myBool: false, otherStuff: 'bla'});
test.myBool // DOES WORK -< This is what I need access to.
However
Obx(() => test)
// DOESNT WORK : A value of Obx cannot be assigned to type MyCustomWidget
// if cast: type 'Obx' is not a subtype of type 'MyCustomWidget'
My Questions:
Is there a way to wrap widgets declared as their types with Obx
If not, is there a way to access the constructor fields of an object declared as Widget
As stated above, I need access to a custom widget's fields for logic to avoid huge boilerplate and dirty code.
Cheers

Related

EF serialize object with nav propertyes

I'm creating an API, and I need to send the data model to the client, for easier processing, so I don't need to implement and maintain the json structure on the client side too, just serialize a new empty object, and give it to the client.
But there comes my problem, if the nav property objects are empty, it get
serialized to an empty array
[]
not to the object in the array.
So my question is, can anyone point me to the right direction, to serialize the object with related properties, like how the swagger documentation does it?
Example for base serialization in MVC: http://pastebin.com/ihF2AeKY
Example for serialization by swagger with nav props, and types: http://pastebin.com/SxxztnDa
Now, I can instantiate the nav props, and add it to the object, then serialize it, but that is clumsy, and not following changes in the objects automatically, like the swagger example does.
EDIT:
This would be ideal, since if i change the base object, or prop relations, the model will automatically follow, but since properties are empty in a new object, unless i populate it by hand, the navigational props will be either null, or an empty list like '[]', like shown in the base example, so i won't get the nav props 'scheme', just the base object. Swagger doing some kind of magic here, to build the full tree, shown in the 2nd pastebin.
[Route("getmodel")]
[HttpGet]
public async Task<Company> GetContactCompanyModel(){
var ret = new Company();
return ret;
}
This is kind of working, but clumsy since i need to insert the props with hand, but this will return the correct model, with populated but empty navigational props.
[Route("getmodel")]
[HttpGet]
public async Task<Company> GetContactCompanyModel(){
var ret = new Company();
ret.Peoples.Add(new People { Address = new Address(), PrivateContact = new ContactDetails(), WorkContact = new ContactDetails()});
ret.ServicePlaces.Add(new ServicePlace { ContactDetails = new ContactDetails(), Address = new Address() });
return ret;
}
This is the output of my hand made new() boilerplate :
http://pastebin.com/C4W6Tvsg as you can see, it contains the empty object for the navigational properties, kinda like how EF would return it for me, so i can just send it to the client, and process it with Angular, even if i add new properties, or fields to it.
So in the end, the question is how can i traverse the object graph, and make a schema from it, kinda like if i would eager load it, but with empty objects.
Hope it's a bit clearer like this.

How to pass viewData back to the controller from partial view?

I have a main view using several partial Views.
Each of these partials use a different model and have post action.
My problem is I need one property from my main view's model to be used in one of my partials.
The partial view which I need to pass this property view is the last stage in the process.
The application reaches a partial view that contains a switch statement , based on the status on the item being queried, decides which partial will be rendered.
I have the property passing that far and even have it included in the Renderaction for the partial but I don't know how to retrieve it in the controller, PartialViewResult.
In the main view:
#{Html.RenderPartial("StatusForm", Model.HeadingDataModel.Status, new ViewDataDictionary { { "PurchaseOrderNumber", Model.AccordionModel.LtsSpecific.PurchaseOrderNumber } });}
PurchaseOrderNumber is what I'm after. The value gets passed to the next stage:
#{
var obj = ViewData["PurchaseOrderNumber"];
}
And within the same view:
Html.RenderAction("FinishedCalibrationForm", obj);
How can I retreive this in my controller ?? The following is not correct I know, but you get the idea.
public PartialViewResult FinishedCalibrationForm( string obj)
All help is appreciated.
Calling Html.RenderAction or Html.Action is largely the same as Url.Action. There's many different overloads, but essentially, the first parameter is the action name, the second parameter is going to be either the controller name or an anonymous object of route values, and the third parameter will be an anonymous object of route values if the second parameter was used for the controller name.
Anyways, whatever you pass in the route values will be used to find and call the associated action, which includes parameters for the action. So, for your example:
Html.RenderAction("FinishedCalibrationForm", new { obj = obj })
Would properly pass obj into your action method. As you have it now, it's going to interpret the value of obj as the controller name the action is within, which is obviously not correct.

TYPO3. Passing objects as arguments in FLUID View Helpers

In the following code booksis a list of book object containing certain properties. And by clicking on the title, it goes to an action display
Fluid template is
<f:for each="books" as="book">
<f:link.action action="display" arguments="{book: book}"> {book.title} </f:link.action>
</f:for>
In controller
public function displayAction(){
print_r($this->request->getArguments());
}
The value of book here is not being set. [book] => null. I try printing the class of it, it still gives me null.
It works fine when I send the arguments as book.title instead of the entire object
What am I missing here? Is this the right way to pass objects as arguments ?
EDIT:
Initially I tried this way.
public function displayAction(\TYPO3\MyExt\Domain\Model\Book $book) {}
But this gives me
Exception while property mapping at property path "":No converter found which can be used to convert from "string" to "TYPO3\MyExt\Domain\Model\Book"
The class Book is something which I created manually and is not registered under extension builder.
You could try it with a parameter for the action:
public function myAction(Tx_MyExt_Domain_Model_Book $book) {
$this->view->assignMultiple(array(
'title' => $book->getTitle(),
'label' => $book->getLabel(),
'content' => $book->getContent()
));
}
EDIT: I updated the example.
Update:
It works with book.title because it's just a string. When you want a complete book object it needs to be found in some storage. A database e.g.. Hence that means you need a model and a repository. Also an entry in the tca and the tables files. Better create your Models with the extension builder, it's much easier and safer for the beginning.

Strongly typed collection with multiple base types in ActionScript (Vector <T,T>)?

Does ActionScript have any way of handling a strongly typed list with multiple base types?
I am actually looking for something such as a Vector<T,T> ?
Is it possible?
Or is the only way of doing it is creating my own class which accepts lets say a String and Number in the constructor and create a Vector<T> out of that class?
No, not by standard. If the items are not one of the primative types you can build a Vector of interfaces, or super classes. For example, a vector of DisplayObjects that contain a mixture of MovieClips and Sprites (which both inherit from the DisplayObject).
For example:
var v:Vector.<DisplayObject> = new <DisplayObject>[
new MovieClip(),
new Sprite(),
new MovieClip()
];
trace(v[0].alpha); // outputs 1
trace(v[0].currentFrame); // error - not a DisplayObject property
In this case the vectors item will only expose the properties and methods of itself that stem from the Vectors type. But this is exactly the reason you should use vectors, it ensures the items type you are handling.
I don't know your specific case or goal, but I would consider why you need a mixed type within a vector. Your alternative option, as you stated, would be to create a wrapper class. The example below is far from complete but a starting point.
class Wrapper {
public var _value:*; // should be private with get/set's
public function Wrapper(value:*) {
if(value is String || value is Number) {
_value = value;
}
}
}
You can't do that, so I would go with your suggestion, which is to create a special class containing two properties (say Number, String) and create a Vector of that.

Referencing getter/setter functions in actionscript 3

How does one get a reference the the getter and setter functions in actionscript 3?
if a method is defined on the calls, e.g.
public function blah():String { ...}
I can get a reference to it by just saying blah or this.blah
How do get a reference to
public function get blah2():String {}
public function set blah2(b:String):void {}
Thanks!
Original response:
Unfortunately, you will not be able to store references to those as functions. The getter and setter methods are actually built around the idea that you shouldn't be able to and they therefore function as a property.
Is there a reason that you need to reference the functions specifically?
The comment I'm responding to:
I want to dynamically add external interface methods based on custom metadata tags, e.g. [External]. I was able to do this for the regular methods, but I'm trying to extend this to getter/setters as well. To do this, I need to get a reference to the function dynamically, so I can execute it with the right args using the apply function.
I think you're better off using a multi-step approach in that case. Since getters and setters function as a property and not a method, it would make sense to test to see if it is a property and then simply assign it a value directly. Would you be able to use this:
if( foo.blah2 is Function )
{
foo.blah2.apply( foo, arr );
}
else
{
foo.blah2 = arr[ 0 ];
}