在 Vue 2 中我确实喜欢这样:
import Component from '@/components/Component.vue';
const VueComponent = {
install(Vue, settings = {}) {
const Constructor = Vue.extend(Component);
const ComponentContainer = new Constructor();
ComponentContainer._props = Object.assign(ComponentContainer._props, settings);
const vm = ComponentContainer.$mount();
document.querySelector('body').appendChild(vm.$el);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我可以像这样调用任何组件方法:
ComponentContainer.add();
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 Vue 3、TS 和 Composition API 制作我的组件,所以我这样做:
import { App, createApp, Component } from 'vue';
import ComponentName from './components/ComponentName.vue';
const VueComponentName: Component = {
install(Vue: App, settings = {}) {
const ComponentContainer = createApp(ComponentName);
ComponentContainer._component.props = Object.assign(ComponentContainer._component.props, settings);
const wrapper = …Run Code Online (Sandbox Code Playgroud) 有时我会在企业应用程序架构中遇到关于继承"超出风格"的评论,但我没有看到描述竞争理论的文章的链接.另外,如果应用程序已经构建而不是从头开始,那么实现是否存在差异?我认为这可能与严重依赖接口有关,但我不确定.
我需要详细解释以下内容:
我们用什么用UIViewController?有什么用?
我有一个类似于以下的类:
class one
{
UINavigationController *nav = ...;
two *secondObject = ...;
// By use of it, I have push the new view class two//ok
}
class two
{
...
}
Run Code Online (Sandbox Code Playgroud)
我怎么secondObject在课堂上使用one?
从窗口开始的类层次结构是什么?
在开发Java Swing GUI时,扩展JFrame总是一个坏主意吗?那么JPanel或其他JComponents呢?还有什么让它变坏?
我需要在我的实体中建模组织层次结构.组织可以是总部,区域负责人,分区域,地区办事处.组织正在执行许多常见功能,但有几个功能是特定的,例如,区域可以执行任务A.还有一些特定于Region的属性(数据).
我使用合成而不使用继承对其进行建模,但现在我只使用单个组织类结束,许多引用取决于组织的类型可以具有有效引用或为null.
对象组成是一种痛苦,现在我通过工厂处理.但现在我主要担心的是开发人员需要记住组织类型是什么以及属性是否对该组织有一定意义.
只是为了清楚我的意思.
public class Organization : IKeyed<int> {
public virtual int Id { get; protected set; }
public virtual string Code { get; set; }
public virtual OrganizationType orgType {get;set;}
public virtual Organization Parent {get;set;}
public virtual IList<Organization> Children {get;set;}
public virtual typeA {get; set;} // only meaningful when organization type is 'Head office'
public virtual typeB {get;set;}// only meaningful when 'Region'
public virtual void AddChild(Organization org){...}
...
}
Run Code Online (Sandbox Code Playgroud)
我应该在这里使用继承吗?或者我在这里错过了一些技巧?
我有一个接口的多种实现,并且我只想以编程方式导出一个。我已经看过了RegistrationBuilder,它的AddMetaData()功能是,但这是为导出定义MetaData,而不是为特定值过滤。例如,我想做这样的事情:
public enum MyClassType { TypeA, TypeB }
public interface IClass {}
public interface ClassMetaData { MyClassType Type { get; } }
[ExportMetadata("Type", MyClassType.TypeA)]
public MyClassA : IClass
{
public MyClassType Type { get { return MyClassType.TypeA; } }
}
[ExportMetadata("Type", MyClassType.TypeB)]
public MyClassB : IClass
{
public MyClassType Type { get { return MyClassType.TypeB; } }
}
//...Then in my bootstrapping class where I set up the MEF container...
var registrationBuilder = new RegistrationBuilder();
registrationBuilder.ForTypesDerivesFrom<IClass>().... …Run Code Online (Sandbox Code Playgroud) 我定义了一个方法和一个函数:
def print(str:String) = println
val intToString = (n:Int) => n.toString
Run Code Online (Sandbox Code Playgroud)
现在我要撰写它们.
我的问题是,为什么两个:
print(_) compose intToString
print(_:String) compose intToString
Run Code Online (Sandbox Code Playgroud)
编译?
但:
(print(_)) compose intToString
(print _ ) compose intToString
Run Code Online (Sandbox Code Playgroud)
编译?
是否有某种形式的内置/术语我不知道它有点但不同的"组成"两个'a -> unit功能产生一个单一的功能; 例如:
let project event =
event |> logDirections
event |> stashDirections
let dispatch (batch:EncodedEventBatch) =
batch.chooseOfUnion () |> Seq.iter project
Run Code Online (Sandbox Code Playgroud)
可能成为:
let project = logDirections FOLLOWEDBY stashDirections
let dispatch (batch:EncodedEventBatch) =
batch.chooseOfUnion () |> Seq.iter project
Run Code Online (Sandbox Code Playgroud)
然后:
let dispatch (batch:EncodedEventBatch) =
batch.chooseOfUnion () |> Seq.iter (logDirections FOLLOWEDBY stashDirections)
Run Code Online (Sandbox Code Playgroud)
我想有人可能会比较它tee(如FSFFAP的铁路导向编程系列中提到的那样).
(它需要将相同的arg传递给两者并且我正在寻求按顺序运行它们而没有任何异常处理技巧问题等)
(我知道我可以做,let project fs arg = fs |> Seq.iter (fun f -> f arg)但我想知道是否有内置的和/或某种形式的组合库我不知道)
我想从:
let a = fun x ->
x
|> f
|> g
Run Code Online (Sandbox Code Playgroud)
这样的事情:
let a = |> f
|> g
Run Code Online (Sandbox Code Playgroud)
我试过了:
let a = (<|) f
|> g
Run Code Online (Sandbox Code Playgroud)
和类似的
为了创建类似表的结构,我在以前的应用程序中以以下格式序列化了行数据:
{ "key1": "...", "key2": "...", "15/04": 1.3, "15/05": 1.2, .... "17/08": 0.8 }
Run Code Online (Sandbox Code Playgroud)
现在,我试图用Go重写它,以便通过动手学习语言。在Go中,可以将两个结构嵌入到另一个结构中,从而将它们组合在一起。从该结构中封送的json将具有平面结构,即,生成的json对象将具有第一和第二个结构的字段的并集,而不会嵌套。这是一个示例:https : //play.golang.org/p/jbJykip7pw(来自http://attilaolah.eu/2014/09/10/json-and-struct-composition-in-go/)
我猜想我也可以将地图嵌入结构中,以便可以使用以下类型定义在json上进行编组:
type Row struct {
key1 string
key2 string
RowData
}
type RowData map[string]float64
...
func main() {
row := Row{
"...",
"...",
RowData{
"15/04": 1.3, "15/05": 1.2, .... "17/08": 0.8,
},
}
}
Run Code Online (Sandbox Code Playgroud)
但这在我的“行”对象中创建了一个字段“行数据”字段,而不是将行数据中的条目追加到所需的平面json对象中:
{ "key1": "...", "key2": "...", "RowData": { "15/04": 1.3, "15/05": 1.2, .... "17/08": 0.8 } }
Run Code Online (Sandbox Code Playgroud)
我想知道,是否有一种方法可以将地图或切片嵌入到结构中,以使生成的json对象是平坦的,而无需MarshalJSON在type上定义函数Row?
composition ×10
c# ×2
f# ×2
inheritance ×2
action ×1
api ×1
class ×1
dictionary ×1
function ×1
go ×1
ios ×1
java ×1
json ×1
mef ×1
methods ×1
oop ×1
pipe ×1
scala ×1
side-effects ×1
struct ×1
swing ×1
typescript ×1
uiview ×1
vue.js ×1
vuejs3 ×1