我正在尝试为使用的第 3 方包编写一个简单的玩笑测试,该包仅导出 ES 模块。它是服务器的包装器http
。
这是我设置的测试存储库(只需运行yarn && yarn jest
即可重现):https://github.com/jamesopti/hocuspocus-testing
无论我尝试什么配置,在尝试运行它时仍然会收到此错误:
Must use import to load ES Module: /Users/j/hocuspocus-testing/node_modules/@hocuspocus/server/dist/hocuspocus-server.esm.js
> 1 | import { Server, Hocuspocus } from '@hocuspocus/server'
| ^
2 | import * as request from 'supertest'
3 |
4 | describe('Server (e2e)', () => {
Run Code Online (Sandbox Code Playgroud)
我已经尝试过的事情:
ES 模块上的 Jest 说明:https ://jestjs.io/docs/ecmascript-modules
在 Jest 配置中使用transformIgnorePatterns
transformIgnorePatterns: ['node_modules/(?!@hocuspocus/)']
使用 Babel 通过babel-jest
将 Jest 配置中的转换设置修改为 '^.+\.jsx?$': 'babel-jest', '^.+\.tsx?$': 'ts-jest'
遇到错误You appear to …
我已经了解到,为了最大限度地提高Android列表视图的效率,您应该只需要尽可能多的充满"行"视图,以适应屏幕.一旦视图移出屏幕,您应该在getView
方法中重复使用它,检查是否convertView
为null.
但是,当您需要2个不同的列表布局时,如何实现这个想法?让我们说它的订单列表和1个布局是针对已完成的订单而另一个布局是针对流程订单.
这是我的代码使用的想法的示例教程.在我的情况下,我将有2行布局:R.layout.listview_item_product_complete
和R.layout.listview_item_product_inprocess
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
if(getItemViewType(position) == COMPLETE_TYPE_INDEX) {
convertView = mInflator.inflate(R.layout.listview_item_product_complete, null);
holder.mNameTextView = (TextView) convertView.findViewById(R.list.text_complete);
holder.mImgImageView = (ImageView) convertView.findViewById(R.list.img_complete);
}
else { // must be INPROCESS_TYPE_INDEX
convertView = mInflator.inflate(R.layout.listview_item_product_inprocess, null);
holder.mNameTextView = (TextView) convertView.findViewById(R.list.text_inprocess);
holder.mImgImageView = (ImageView) convertView.findViewById(R.list.img_inprocess);
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
thisOrder = (Order) …
Run Code Online (Sandbox Code Playgroud) 我想看看是否有人使用新的Android API级别17附带的FragmentTabHost自定义选项卡.
我很高兴能够在我的ViewPager SherlockFragments中嵌入一个tabHost,但是我很难做一些简单的事情,例如将标签移动到底部或更改标签的布局.
有谁见过使用这个功能的好例子?
这是我在Android文档中找到的唯一示例,而且几乎没有任何描述它的用法.它似乎也忽略了布局中定义的内容R.id.fragment1
.
我想我的问题是,如果有人遇到过一个很好的教程:FragmentTabHost或者他们是否知道如何a)将嵌套标签置于底部或b)更改所述标签的布局.
我已经尝试了所有常用方法,但由于看起来XML布局文件被覆盖,我没有太多运气.
private FragmentTabHost mTabHost;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setContentView(R.layout.fragment_tabs);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FragmentStackSupport.CountingFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
LoaderCursorSupport.CursorLoaderListFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
LoaderCustomSupport.AppListFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
return mTabHost;
}
Run Code Online (Sandbox Code Playgroud)
在做了一些研究后,似乎可能会在支持库中初始化FragmentTabHost时出现故障.Google代码上的用户提供了以下建议:
FragmentTabHost.java
private void initFragmentTabHost(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs,
new int[] { android.R.attr.inflatedId }, 0, 0);
mContainerId = a.getResourceId(0, 0);
a.recycle();
super.setOnTabChangedListener(this);
// If owner hasn't made its own …
Run Code Online (Sandbox Code Playgroud) 我在Laravel中通过POST进行基本记录更新时遇到了麻烦.
我已经捕获了数组中的所有发布数据,如果现有的Order#为0,那么我创建一个新记录(工作正常).否则我更新现有记录.
Order.php
class Order extends Eloquent {
public static $table = 'my_orders';
}
Run Code Online (Sandbox Code Playgroud)
routes.php文件
//Handle a new order POST
Route::post('order', array('do' => function() {
$thisOrder = array(
'qty' => Input::get('quantity'),
'desc' => Input::get('description'),
);
$thisOrderID = Input::get('orderNo');
//CHECK FOR NEW OR EXISTING ORDER
if($thisOrderID > 0) {
//THIS FUNCTION SOMEHOW RETURNS THE FUNCTION CALL AND DOESNT CONTINUE PAST
//AND THE RECORD IS NOT UPDATED
$updateOrder = Order::update($thisOrderID, $thisOrder);
}
}
Run Code Online (Sandbox Code Playgroud)
更新:上面的代码实际上工作.我有一个验证错误,导致函数提前返回.
这里设置的重现性最低:https://github.com/jamesopti/webpack_playground/tree/resolve_url_loader_issue
我试图用resolve-url-loader
我的scss url()
图像路径添加一个hashname ,但我有一点时间让它与webpack 4一起工作.我有一堆图像/static/img/**
在我的SCSS中被引用,如:
span.arrow {
background: url(/static/img/audiences.png);
}
Run Code Online (Sandbox Code Playgroud)
这最终在我的CSS中完全相同(resolve-url-loader找不到它们)
当我通过webpack运行以下配置时,我看到解析加载程序正在找到正确url()
的路径,但调试模式是说找不到.
resolve-url-loader: /static/img/audiences.png
/Users/usr1/webpack_playground/src
/Users/usr1/webpack_playground/static/img
NOT FOUND
Run Code Online (Sandbox Code Playgroud)
是否有一些输出配置不正确?我尝试了各种设置组合无济于事:
loader: 'resolve-url-loader',
options: {
debug: true,
root: path.join(__dirname, './static/img'),
includeRoot: true,
absolute: true,
},
Run Code Online (Sandbox Code Playgroud)
我的最终目标是将文件加载器转换为/ dist散列版本:
span.arrow {
background: url(/static/img/audiences-dhsye47djs82kdhe6.png);
}
Run Code Online (Sandbox Code Playgroud)
// Webpack规则配置
rules: [
{
test: /\.(png|jpg|gif)$/,
include: [
path.resolve(__dirname, './static/img'),
],
use: {
loader: 'file-loader',
options: {
name: '[name]-[hash].[ext]',
},
},
},
{
test: /\.svg$/,
use: {
loader: 'svg-inline-loader', …
Run Code Online (Sandbox Code Playgroud) 始终提供来自 CDN EDGE 缓存的内容,无论内容多么陈旧。尽可能在后台刷新它。
我有一个NextJS应用程序,它在服务器端呈现一些 React 组件并将它们交付给客户端。对于这个讨论,让我们只考虑我的主页,它是未经身份验证的,对每个人都是一样的。
我想要的是将服务器呈现的主页缓存在 CDN 的 EDGE 节点上,并尽可能多地或始终从该缓存中为终端客户端提供服务。
从我读到的内容来看,CDN(如 Fastly)正确支持缓存相关的标头设置,例如Surrogate-Control
并且Cache-Control: stale-while-revalidate
应该能够做到这一点,但实际上,我没有看到它像我期望的那样工作。我看到的是:
考虑以下时间线:
[T0] - Visitor1 请求www.mysite.com
- CDN 缓存完全冷,因此请求必须返回我的源(AWS Lambda)并重新计算主页。返回带有标头Surrogate-Control: max-age=100
和 的响应Cache-Control: public, no-store, must-revalidate
。然后访问者 1 提供了主页,但他们不得不等待高达 5 秒钟!呸!愿没有其他游客遭受同样的命运。
[T50] - 访问者 2 请求www.mysite.com
- CDN 缓存包含我的文档并立即将其返回给访问者。他们只需要等待 40 毫秒!惊人的。在后台,CDN 从我的源重新获取最新版本的主页。原来它没有改变。
[T80] -www.mysite.com
向主页发布新内容,使任何缓存的内容真正过时。该网站的V2现已上线!
[T110] - 访问者 1 返回到www.mysite.com
- 从 CDN 的角度来看,自访问者 2 的请求以来只有 60 …
我有一个电子应用程序,最初是随个人开发人员的证书一起分发的。
我现在想使用我组织的证书签署该应用程序的下一个更新,但是当我这样做时,现有安装(在自动更新时)会抛出不满足代码要求的错误。
有没有办法使用旧证书和新证书正确签署电子应用程序?我想防止我现有的用户被打扰。
任何帮助表示赞赏!
谢谢
code-signing code-signing-certificate codesign electron electron-builder
我想实现一个更高阶的反应组件,可用于轻松跟踪任何React组件上的事件(如点击).这样做的目的是轻松将点击(和其他事件)挂钩到我们的第一方分析跟踪器中.
我遇到的挑战是React合成事件系统需要事件(如onClick
)绑定对DOM元素的反应,如a div
.如果我正在包装的组件是自定义组件,就像通过更高阶函数实现的每个HOC一样,我的单击事件无法正确绑定.
例如,使用此HOC,onClick
处理程序将触发button1,但不触发button2.
// Higher Order Component
class Track extends React.Component {
onClick = (e) => {
myTracker.track(props.eventName);
}
render() {
return React.Children.map(
this.props.children,
c => React.cloneElement(c, {
onClick: this.onClick,
}),
);
}
}
function Wrapper(props) {
return props.children;
}
<Track eventName={'button 1 click'}>
<button>Button 1</button>
</Track>
<Track eventName={'button 2 click'}>
<Wrapper>
<button>Button 2</button>
</Wrapper>
</Track>
Run Code Online (Sandbox Code Playgroud)
CodeSandbox带有工作示例: https ://codesandbox.io/embed/pp8r8oj717
我的目标是能够像这样使用HOF(可选择作为装饰器)来跟踪任何React组件定义的点击.
export const withTracking = eventName => Component => props => {
return (
<Track …
Run Code Online (Sandbox Code Playgroud) 我Orders_Controller
在 Laravel 中有一个名为 getOrders($user)的函数。它调用原始数据库查询并构建要返回的 JSON 数组。
我不知道如何从我的路由文件中调用这个函数。
基本上我在路由中收到一个 POST,插入新的订单,然后我想从这个路由函数调用 getOrders(user) 来获取给定用户的所有现有订单。
有人能帮我弄清楚如何从 Routes.php 中调用这个函数吗?
路由.php
//Handle a new order POST
Route::post('order', array('do' => function() {
...
... //HANDLE POST DATA AND INSERT NEW ORDER
...
//GET ALL ORDERS FOR THIS USER FROM ORDER CONTROLLER
$userOrders = Order_Controller::myOrders($thisUser);
}
Run Code Online (Sandbox Code Playgroud)
order.php(在控制器文件夹中)
class Order_Controller extends Base_Controller
{
public function myOrders($user){
return DB::query("SELECT ...");
}
}
Run Code Online (Sandbox Code Playgroud) 我发现自己在3个独立的活动中为我的actionBar(actionBarSherlock)列表重写了相同的代码.所有3个都使用相同的actionBar,其中有3个项目启动活动#1,#2,#3.
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayAdapter<CharSequence> list = ArrayAdapter
.createFromResource(this, R.array.action_list, android.R.layout.simple_dropdown_item_1line);
list.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
getSupportActionBar().setListNavigationCallbacks(list, this);
getSupportActionBar().setListNavigationCallbacks(adapter, this);
getSupportActionBar().setSelectedNavigationItem(position);
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
在这种情况下,我应该使用1个带有3个片段的活动吗?我的活动是列表视图,地图视图和表单视图.我不确定这是否是使用Fragments的正确案例,因为在我的案例中,每个视图都使用整个屏幕.
使用3种不同的活动,我可以创建一个新类,其唯一目的是使用上面的代码为我配置ActionBar,所以初始化代码只在一个地方吗?
就像是:
public class setupActionBar {
private ActionBar myBar;
public setupActionBar(ActionBar myBar){
this.myBar = myBar;
//Do Initialization on myBar;
}
public ActionBar getMyBar(){
return myBar;
}
}
Run Code Online (Sandbox Code Playgroud) android ×3
java ×3
laravel ×2
post ×2
cdn ×1
cloudflare ×1
code-signing ×1
codesign ×1
controller ×1
electron ×1
es6-modules ×1
fastly ×1
javascript ×1
jestjs ×1
next.js ×1
node.js ×1
php ×1
reactjs ×1
sass-loader ×1
typescript ×1
webpack ×1