I have just started to create Haxe externs (strictly typed class definitions)
based on the yuidoc output from the ember source.
Now I need help to understand how to implement the kind of mixing architecture special to Ember.
For example the Ember.Object extends the Ember.CoreObject - however I wasn't able to locate any constructor inside the latter - is there any direct call to new Something() in Ember at all?
Then Ember.Object uses Ember.Observable which in turn imports cacheFor from the ember-metal / lib / computed.js module - is this relation reflected inside the data.json output of yuidoc or will I need to parse the sources directly in order to collect all methods into my class definitions?
is there any direct call to new Something() in Ember at all?
For the most part, no. You're supposed to call Class.create() not new Class().
is this relation reflected inside the data.json output of yuidoc or will I need to parse the sources directly in order to collect all methods into my class definitions?
The data.json file should contain most of the documentation written. The problem you'll experience is that not everything is documented (mostly private API).
Where can I find the Container Class API docs?
In the source code.
Related
Creating in-repo-addon in Ember.JS gives a lot of possibilities. Today I've stumbled into a case when I wanted to register all classes in directory (for example my-dir) into Dependency Injector (same way it's done with services by Ember, but I wanted to use some other namespace).
For example I want to allow developer to create multiple classes inside proxy directory, and register all of them in DI under proxy: namespace. So later we can use:
Ember.Component.extend({
myProxy: Ember.inject('proxy:my'),
});
You'll need to do this using an initializer. More details on this here: https://guides.emberjs.com/v2.12.0/applications/dependency-injection/
The hard part may be getting all proxy items in s folder to automatically register ...
Edit
Looks like I didn't spend enough time thinking about this. You should be able to do at least part of this easily. There are two parts to this.
Part 1
Ember currently uses the ember-resolver to handle lookups for various items. If you check the tests for the resolver you'll notice that you should be able to map in anything you want: https://github.com/ember-cli/ember-resolver/blob/master/tests/unit/resolvers/classic/basic-test.js
So in your case, if you do a Ember.getOwner(this).lookup('proxy:main') from within an Ember instantiated class (a route, controller or component for instance) it would look in app/proxy/main.js which your addon could be populating.
Details on the Ember.getOwner lookup are available here: https://emberjs.com/api/classes/Ember.html#method_getOwner
Part 2
So at this point you can lookup proxies (which would be doable in an init method). But if we want to get truly elegant we'd want to allow Ember.inject.proxy('main') syntax.
Doing so would involve calling a private method inside of Ember.inject in an initializer. Because that naming scheme is changing in the new Javascript modules RFC, it may be unwise to try to add this syntactic sugar ...
So I'd advise avoiding touching that private API unless it's really important to your app design.
Let's assume we have a very large codebase and want to namespace a group of functionally-related code under a folder structure. Say we have a bunch of files related to Admin so we create an app/models/admin folder and place files like admin.rb and admin_accounts.rb under the models/admin folder.
Questions:
1. Do these classes now need to be wrapped in an admin module or does Rails do this for us automatically?
2. When creating a new admin, is there a way for us to not have to call it like Admin::Admin.rb or Admin::AdminAccount.new. The call sites range in the 100s. Do we have to change each call site to reference the wrapping module now? Or is there a way around this with the autoload feature?
In short, what's best practice? Do we now need to wrap the classes in a module? IF so, does that mean we now need to preface Admin.new and AdminAccount with the module? Is this necessary?
I created a table following the flatbuffers tutorial and compiled it to C++ code. Say, its name is Doc.
In the tutorial, it is said:
Regardless of whether you used CreateMonster or MonsterBuilder, you
now have an offset to the root of your data, and you can finish the
buffer using:
FinishMonsterBuffer(fbb, mloc);
However, I can't find any method named FinishDocBuffer. The generated Doc class only has one method named Verify() in addition to getters. The generated DocBuilder class only has one method named Finish(). And there's only one function named CreateDoc() defined outside of those two classes.
Did I do something wrong, or should the official doc be updated?
FYI, I'm using latest flatbuffers code cloned from the git repo.
Update:
I found the example code didn't call any Finish*Buffer() method either.
Found the reason. I need to add this line to my doc.fbs file:
root_type Doc;
I am wondering how to automatically include helper into to the all models files of the component, that i only need to create object from helpers class in models files?
Avoid using require_once, and use the proper Joomla methods for including helper classes
JLoader::register('ClassName', 'path_to_class');
Put this snippet in the beginning of your component entry controller. Joomla will then autmotically load the class only when it's needed.
By using the regular PHP require_once you will slow down your code, since the file will instantly be loaded into memory, even if it's not needed.
I am working on a Django app and I have a class which reads the contents of a file and returns a Django model. My question is where do I store this class in the file system? All this does is reads the file, populates a Django model and returns it.
Thanks
There is nothing special about a Django application: it's just a Python package. Technically you can put the class anywhere you can import.
With that being said, it's best to keep related code bundled together. It sounds like a good place for this particular class is in the file that declares the Model it returns.
On the other hand it might be logical to throw it into the application's __init__.py file.
You could also make a utils, etc, admin, scripts . . . folder/package to put utility classes and scripts if it's meant to be used for administration and site maintenance.
In the end it's more about how you want to organize your project, but technically it can live just about anywhere.