我在网上找到很多Sencha Touch的例子,并没有真正专注于正确的视图封装.因此,即使按钮深度嵌套在视图中,Controller也会监听每个按钮的事件.换句话说,视图泄漏的内部从来都不是一件好事.
我找到了一个很好的教程,鼓励你创建有意义的观点,听取当地的事件,并提出有意义的商业活动等.
http://miamicoder.com/2012/how-to-create-a-sencha-touch-2-app-part-2/
但是,到目前为止我无法弄清楚的一件事是如何最好地缓存嵌套组件实例.考虑这个例子:
Ext.define("NotesApp.view.NotesListContainer", {
extend: "Ext.Container",
alias: "widget.noteslistcontainer",
initialize: function () {
this.callParent(arguments);
var newButton = {
xtype: "button",
text: 'New',
ui: 'action',
handler: this.onNewButtonTap,
scope: this
};
var topToolbar = {
xtype: "toolbar",
title: 'My Notes',
docked: "top",
items: [
{ xtype: 'spacer' },
newButton
]
};
this.add([topToolbar]);
},
onNewButtonTap: function () {
console.log("newNoteCommand");
this.fireEvent("newNoteCommand", this);
},
config: {
layout: {
type: 'fit'
}
}
});
Run Code Online (Sandbox Code Playgroud)
比方说,我们要添加一个方法setSpecialUIState给我们的NotesListContainer.当它被调用时,我们想要做一些事情newButton(例如隐藏它).如何在newButton不滥用的情况下获取对实例的访问权限Ext.getComp() …
我想知道当没有新的请求进入时,ASP.NET(MVC)应用程序会运行多长时间?假设我正在使用IOC容器,并且为客户端提供了一个Singleton Object.据我所知,它将提供不同的页面请求.但是没有新的请求进来会活多久?是否有任何超时(可能通过IIS配置)说我的应用程序何时关闭?
我编写了这个非常基本的程序来检查编译器在幕后做了什么:
class Program
{
static void Main(string[] args)
{
var increase = Increase();
Console.WriteLine(increase());
Console.WriteLine(increase());
Console.ReadLine();
}
static Func<int> Increase()
{
int counter = 0;
return () => counter++;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我用Reflector查看代码时,我确实看到编译器为我的闭包生成了一个类:
[CompilerGenerated]
private sealed class <>c__DisplayClass1
{
// Fields
public int counter;
// Methods
public int <Increase>b__0()
{
return this.counter++;
}
}
Run Code Online (Sandbox Code Playgroud)
那很好,我知道他需要这样做来处理我的关闭.但是,我看不到他是如何使用这个类的.我的意思是我应该能找到在某处实例化"<> c__DisplayClass1"的代码,我错了吗?
编辑
如果我点击增加方法,它看起来像这样:
private static Func<int> Increase()
{
int counter = 0;
return delegate {
return counter++;
};
}
Run Code Online (Sandbox Code Playgroud) 我知道很多关于Linq和它的内部运作的文章.受Jon Skeets EduLinq的启发,我想揭开Linq运营商背后的神秘面纱.所以我试图做的是实现Linqs Select()方法,一见钟情听起来很无聊.但我实际上要做的是在不使用yield关键字的情况下实现它.
所以这是我到目前为止所得到的:
class Program
{
static void Main(string[] args)
{
var list = new int[] {1, 2, 3};
var otherList = list.MySelect(x => x.ToString()).MySelect(x => x + "test");
foreach (var item in otherList)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
public static class EnumerableEx
{
public static IEnumerable<R> MySelect<T, R>(this IEnumerable<T> sequence, Func<T, R> apply)
{
return new EnumerableWrapper<R, T>(sequence, apply);
}
}
public class EnumerableWrapper<T, O> : IEnumerable<T>
{
private readonly IEnumerable<O> _sequence;
private readonly Func<O, T> …Run Code Online (Sandbox Code Playgroud) 我有一堆F#脚本(fsx),我用它来满足我的基本部署需求.我只是右键单击它们并说"运行F#interactive"
但是,有时脚本失败,我想保持交互式控制台运行.到目前为止,我还没有找到一个很好的方法来实现这一目标.
我尝试手动启动fsi.exe但是如何从那里启动我的脚本?
我有时想从不同的存储库中选择一系列提交.我知道有两种方法可以做到这一点.
1.
git checkout myBranch
git cherry-pick begin..end
Run Code Online (Sandbox Code Playgroud)
要么
git rebase --onto myBranch begin end我发现第一个版本更容易记住.然而,我读了很多关于如果采摘与挑选相比,挑选樱桃是多么邪恶,因为它有点打破了历史.但我还没想到的是,如果樱桃选择一系列提交或者将它们重新定位,那么它们之间是否存在差异--onto
我倾向于认为应该没有区别.我错了吗?
我设法再次遇到一个终身问题,我似乎无法自己解决.
编译器告诉我无法推断自动强制的适当生命周期

我试图遵循编译器建议并在handle_request方法中引入了生命周期注释.
fn handle_request<'a>(&self, req: &Request, res: &'a mut ResponseWriter) {
fn set_headers(req: &Request, res: &mut ResponseWriter) {
//probably not important for the example
}
match &req.request_uri {
&AbsolutePath(ref url) => {
match self.router.match_route(req.method.clone(), url.clone()) {
Some(route_result) => {
set_headers(req, res);
let floor_req = request::Request{
origin: req,
params: route_result.params.clone()
};
let floor_res = response::Response{
origin: res
};
(route_result.route.handler)(floor_req, &mut floor_res);
},
None => {}
}
},
_ => set_headers(req, res)
}
}
Run Code Online (Sandbox Code Playgroud)
我之前有代码工作,但现在我想http::server::ResponseWriter在我自己的Response …
我想知道是否有办法弄清楚变量是堆栈还是堆分配.
考虑一下:
struct SomeStruct;
fn main() {
let some_thing = Box::new(SomeStruct);
println!("{:p}", some_thing);
foo(&*some_thing);
}
fn foo (bar: &SomeStruct) {
println!("{:p}", bar);
}
Run Code Online (Sandbox Code Playgroud)
版画
0x1
0x1
Run Code Online (Sandbox Code Playgroud)
然后
struct SomeStruct;
fn main() {
let some_thing = &SomeStruct;
println!("{:p}", some_thing);
foo(some_thing);
}
fn foo (bar: &SomeStruct) {
println!("{:p}", bar);
}
Run Code Online (Sandbox Code Playgroud)
版画
0x10694dcc0
0x10694dcc0
Run Code Online (Sandbox Code Playgroud)
我可以看到堆分配版本的内存地址要短得多,但我不知道这是否是一种可靠的方法来区分它.我想知道是否有类似的东西std::foo::is_heap_allocated()
我有时看东西好像<T=Self>还是T=()在普通的结构/特性.我怀疑这与泛型类型的默认类型有关T.我找不到任何文件.
我的问题是:
<T=Self: 'static)?我试图环绕我的头Rc,并RefCell在生锈.我想要实现的是对同一个对象进行多个可变引用.
我想出了这个虚拟代码:
use std::rc::Rc;
use std::cell::RefCell;
struct Person {
name: String,
mother: Option<Rc<RefCell<Person>>>,
father: Option<Rc<RefCell<Person>>>,
partner: Option<Rc<RefCell<Person>>>
}
pub fn main () {
let mut susan = Person {
name: "Susan".to_string(),
mother: None,
father: None,
partner: None
};
let mut boxed_susan = Rc::new(RefCell::new(susan));
let mut john = Person {
name: "John".to_string(),
mother: None,
father: None,
partner: Some(boxed_susan.clone())
};
let mut boxed_john = Rc::new(RefCell::new(john));
let mut fred = Person {
name: "Fred".to_string(),
mother: Some(boxed_susan.clone()),
father: Some(boxed_john.clone()),
partner: …Run Code Online (Sandbox Code Playgroud) rust ×4
c# ×2
asp.net-mvc ×1
cherry-pick ×1
extjs4 ×1
f# ×1
f#-scripting ×1
generics ×1
git ×1
git-rebase ×1
heap ×1
iterator ×1
lifetime ×1
linq ×1
reflector ×1
sencha-touch ×1
singleton ×1
stack ×1
yield ×1