I have a live template useS for
const [$VAR1$, set$VAR2$] = useState($END$);
where useState is an external variable that has to be imported like so:
import { useState } from "react";
Whenever this template is used, the import should be automatically added to the current file at the top.
The template is used within JS functions, therefore I can not just add an import to the live template, since the import will be placed inline then.
Is there a special pattern for that?
Doesn't work currently, please follow WEB-37425 for updates
Related
I'm writing unit test in remix-ide and I want to call functions from different addresses within a single test.
The remix-tests Github page says that you can use import "remix_accounts.sol";, but I get URL not parseable: remix_accounts.sol. How to fix that? Or maybe there's another way to call from various addresses?
Import files with relative paths, in your case, modify the following
import "remix_accounts.sol";
to
import "./remix_accounts.sol";
Also, notice that remix doesn't allow import from an ancestor directory, for example:
import "../remix_accounts.sol";
I am experimenting with C++ modules, using clang 5.0, and I am trying to understand how can I export from one module something that I have imported from another module. Is that even possible?
For example, I'd like to have something like this:
// root.hehe.cppm
export module root.hehe;
class hehe
{
};
and this:
// root.cppm
export module root;
import root.hehe;
export class hehe; // ... doesn't work!
export hehe; // Also doesn't work!
export import root.hehe; // No dice!
So that in the end I can do something like
import root;
// ...
hehe myhehe;
Is such a thing possible? I also tried figuring out if there could be a way to import all the submodules of root, like import root.*, but that didn't work either.
In C++20 (not whatever prototype version in Clang), you can use either of
export using ::hehe;
export using hehe=hehe;
to do this, with two caveats:
The first form must always use a qualified name (because the syntax was introduced long ago to copy names between namespaces).
You must first be able to use the name you imported, which is not the case in your example because root.hehe did not export it. (For the type alias approach, it’s sufficient to be able to name it via decltype or so.)
You can also use export import root.hehe; to reexport everything exported by the module being imported. There is no wildcard import syntax: module names with dots have no semantics whatsoever (in C++20).
How to get current or default template engine here?
#register.filter
def myfilter(instance):
pass
You can get the instance of the default template engine (the first configured) doing the following:
from django.template.engine import Engine
current_engine = Engine.get_default()
More information:
http://django.readthedocs.io/en/latest/ref/templates/api.html#django.template.Engine.get_default
An extract of that documentation:
static Engine.get_default()
Returns the underlying Engine from the first configured
DjangoTemplates engine. Raises ImproperlyConfigured if no engines are
configured.
It’s required for preserving APIs that rely on a globally available,
implicitly configured engine. Any other use is strongly discouraged.
See also the source code of that staticmethod:
http://django.readthedocs.io/en/latest/_modules/django/template/engine.html#Engine.get_default
from settings import TEMPLATES
TEMPLATES[0]['BACKEND']
or
from django.template.backends.django import DjangoTemplates
I think I do not understand well the modules hierarchy in an ember-cli app.
I need to
import QueryParams from 'ember-routing/system/query_params';
in one of my app services.
but the console shouts at me
Error: Could not find module 'ember-routing/system/query_params' imported from 'my-app/services/menu'
What path should I use to import this module ?
Thanks
I wanted to do the same thing; get the QueryParams class so I could create a higher-level link-to that accepted a query param key.
Luckily QueryParams is a really basic class: you can create your own (compatible for use in {{link-to}} version of it:
import Ember from 'ember';
const { Object } = Ember;
export default Object.extend({
isQueryParams: true,
values: null,
});
Taken from QueryParams source
I'm guessing that you got that path from the Ember source. Unfortunately, Ember's internal package structure is not exposed externally to other module loaders such as Ember-CLI's. As of now, the only way to access the Ember library and its internals is to import the main object from ember and use that.
// This...
import Ember from 'ember';
const Controller = Ember.Controller;
// Not this...
import Controller from 'ember-runtime/controllers/controller';
Unfortunately for you the QueryParams object is not exposed in this manner. However, that object is simply an implementation detail and I can't see a reason why you would need it in your app. I'm guessing you might be mistaken as to what that actually does. The guide on query parameters might help you there.
It is possible to import from ember internals. But it is considered as hack.
const metal = Ember.__loader.require('ember-metal');
Above is how to import from ember-metal to import ember-routing/system/query_params review loader registry for proper import
const registry = Ember.__loader.registry
console.log(registry);
I am using Ember-CLI and now I faced the problem of importing AmplifyJS in my project. I downloaded Amplify using Bower however the library is not in an ES6 format. Therefore, when I try to use it in my project, I simply can't import it.
Basically I would want to do:
import Amplify from amplify;
//use amplify here
Brocfile.js
app.import('bower_components/amplify/lib/amplify.js');
Since a lot of libraries are no in the ES6 format yet, my question is: "Is there a way to easily import or use ES5 librairies in ES6".
If not, what is the recommended way of doing that in Ember?
You can't import Amplify from amplify; because it's not a module.
You've almost got it but just don't try to import the library. You need to reference it as a global the way that you would outside of an ember-cli app.
From the docs:
Provide the asset path as the first and only argument:
app.import('bower_components/moment/moment.js');
From here you would use the package as specified by it’s documentation, usually a global variable. In this case it would be:
import Ember from 'ember';
/* global moment */
// No import for moment, it's a global called `moment`
// ...
var day = moment('Dec 25, 1995');
Note: Don’t forget to make JSHint happy by adding a /* global MY_GLOBAL */ to your module, or by defining it within the predefs section of your .jshintrc file.
-- http://www.ember-cli.com/#standard-non-amd-asset
If you look at line 15 of the code https://github.com/mikehostetler/amplify/blob/master/lib/amplify.js#L15, library is attaching itself to global which is passed in here https://github.com/mikehostetler/amplify/blob/master/lib/amplify.js#L124
So basically you can directly use the global version of library anywhere like amplify.subscribe(...)