我目前正在使用角动画.因此,我想出了将动画附加到组件的两种可能方法.在下文中,我将它们描述为State/Transition-Animations和Query-Animations.
在这个问题中,我主要想知道一种或另一种方式是否存在性能差异!?
1.状态/过渡动画
html的
<div [@animation_foo]/>
Run Code Online (Sandbox Code Playgroud)
.TS
trigger('animation_foo', [
state('true', style({...}),
state('false', style({...})
transition('true => false', animate(...)
]
Run Code Online (Sandbox Code Playgroud)
2.查询动画
html的
<div [@animation_foo]>
<div class="bar"/>
</div>
Run Code Online (Sandbox Code Playgroud)
.TS
trigger('animation_foo', [
query('.bar', style({...}), animate('10ms', style({...}))
]
Run Code Online (Sandbox Code Playgroud)
进一步思考:
我主要关心点2.查询是:
环境/目标平台:我知道它可能与休闲Web应用程序无关,但我尝试在具有多个路由器,嵌套组件和大量ngIf的ngFors的大型企业应用程序中思考,以便我个人可以想象查询所有可能的做一些努力.
浏览器:我知道浏览器的行为方式不同.我个人目前只对Chrome感兴趣 - 但为了社区,一般的答案会很棒.
如果您有任何重要的信息需要注意,分享(错误,...)会很好
上周我回答了一个 RxJS问题,在那里我与另一位社区成员进行了讨论:“我应该为每个特定的副作用创建订阅,还是应该尽量减少订阅?” 我想知道在完全反应式应用程序方法或何时从一种切换到另一种方法方面使用什么方法。这将帮助我和其他人避免不必要的讨论。
设置信息
什么是副作用(Angular 示例)
value$ | async)@Output event = event$)示例用例:
foo: () => void; bar: (arg: any) => voidhttp$: Observable<any>; click$: Observable<void>foo在http$发出后调用并且不需要值bar在click$发出后调用,但需要当前值http$案例:为每个特定的副作用创建订阅
const foo$ = http$.pipe(
mapTo(void 0)
);
const bar$ = http$.pipe(
switchMap(httpValue => click$.pipe(
mapTo(httpValue)
)
);
foo$.subscribe(foo);
bar$.subscribe(bar);
Run Code Online (Sandbox Code Playgroud)
案例:一般最小化订阅
http$.pipe(
tap(() => foo()),
switchMap(httpValue => click$.pipe( …Run Code Online (Sandbox Code Playgroud) 我想设置tintColor我的png Image动态.Actuall我试图在state属性上设置颜色,并使用单独的函数更改它们setState.
我的代码是这样的(期望在以下代码片段的上方和周围一切正常):
class dynamicImageColor extends Component{
constructor(props) {
super(props);
this.state = {
myDynamicColor: '#ffffff'
}
}
changeColor(bool){
if(bool === true)
{
this.setState({
myDynamicColor: '#932727'
})
}if(bool === false)
{
this.setState({
myDynamicColor: '#ffffff'
})
}
}
render(){
return(
<Image source={myPNGImage} style={styles.PNGImageStyle}/>
)
}
var styles = StyleSheet.create({
PNGImageStyle: {
tintColor: this.state.myDynamicColor,
width: 25,
height: 25
}
Run Code Online (Sandbox Code Playgroud)
如果我设置tintColor静态,上面代码中的所有内容都可以正常工作.而函数changeColor(bool)在其他一些不相关的地方被调用并且工作正常.
我的实际问题是我收到错误消息:
undefined不是对象(evaluate'this.state.myDynamicColor
我还想看看是否有错误的值传输.但控制台显示正确的'#ffffff'hex_code格式myDynamicColor
我不知道进一步,帮助会非常好.如果你给我一个更好的解决方案,我也很高兴:)
谢谢BR Jonathan
预先信息:
我仍然打开了一个Firebase项目,并且我仍在成功使用Firebase数据库(因此可以 firebase.initializeApp(config) 正常工作)。我在Firebase Storage的“ / Images / ” 文件夹中上传了几张图片,并将它们命名为image1.jpg,image2.jpg ..
React-Native:0.31.0,Firebase:3.3.0
我想要的是:
我想从Firebase存储中获取映像并将其放入 <Image>
我实际上做了什么:
var storageRef = firebase.storage().ref('Images/image1.jpg');
//1. Try:
storageRef.getDownloadURL().then(function(url) {
console.log(url);
)}
//2. Try:
var sampleImage = storageRef.getDownloadURL().then(function(url) {
console.log(url);
)}
//3. Try:
var sampleImage = storageRef.getDownloadURL();
Run Code Online (Sandbox Code Playgroud)
有关代码的信息:
该代码没有到达console.log(url)点
2.1。试图在对象中使用sampleImageas :空白图片source<Image>
2.2。尝试log过sampleImage:undefined
2.3。尝试log过url:没有达到这一点
3.1。试图在对象中使用sampleImageas :空白图片source<Image>
3.2。尝试log过sampleImage …
我尝试过的事情包括以下内容,其中值是我想要查找总和的值的数组。
我还从 rxjs 添加了必要的功能,如下所示:我收到一条错误消息
类型错误:Rx.Observable.from(...).sum 不是函数
const { merge , interval ,from} = rxjs;
const { tap ,take ,sum } = rxjs.operators;
var sumSource = Rx.Observable.from(values).sum(function (x) {
return x;
});
var subscription = sumSource.subscribe(
function (x) {
console.log('Next: ' + x);
x.target.value = x;
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
}
);
Run Code Online (Sandbox Code Playgroud)
互联网上关于总和的信息不多。有任何输入可以修复并获得总和吗?
关于角度材料的官方文档,日期选择器组件提供了两个输出,如果日期选择器打开 ( openedStream) 或关闭 ( closedStream) ( datepicker-api )。
如果我打开和关闭日期选择器,我将不会从这些事件中得到任何信息,并且我<div>{{ message }}</div>仍然是空的并且没有任何价值。
我的实际设置
export class NoteCreateComponent {
public message = "";
constructor(){}
toggleDatePicker(picker){
picker.open();
}
}Run Code Online (Sandbox Code Playgroud)
<div>{{ message }}</div>
<button (click)="toggleDatePicker(picker)" mat-icon-button>
<mat-datepicker
(openedStream)="message=$event"
(closedStream)="message=$event" #picker>
</mat-datepicker>Run Code Online (Sandbox Code Playgroud)
预期的结果是我打开或关闭日期选择器(不仅仅是通过单击按钮)我得到一个反馈。
如果您想迭代数组以查看某些元素是否通过条件,请执行以下操作:
let result = [1, 34, 65, 3, 7].some(entry => entry > 10)
// result => true
Run Code Online (Sandbox Code Playgroud)
执行此操作的 rxjs 等效项是什么?我想象它是这样的(这并不完全正确):
// functions return Observable<number>
from([fn1, fn2, fn2]).pipe(
map(fn => fn()),
takeUntil(data > 100)
).subscribe(data => console.log(`result:${data}`)
Run Code Online (Sandbox Code Playgroud)
(fn 的返回值始终是异步的)
我想执行一些顺序代码,但我无法从 combineLatest 中提取数据
const { datosPersona, participante } = await combineLatest(
this.store.select('datosPersona'),
this.store.select('participante')
).pipe(
map((data) => ({ datosPersona: data[0], participante: data[1] }),
).toPromise();
Run Code Online (Sandbox Code Playgroud) 是否可以在 kotlin 的一行中条件赋值?
设置
var foo: String
if (x != 0) {
foo = x
}
Run Code Online (Sandbox Code Playgroud)
目标
// nothing is set if condition is false
foo = if (x != 0) x
Run Code Online (Sandbox Code Playgroud)
不想要
// null is set if condition is false
foo = takeIf{ x != 0 }.let{ x }
Run Code Online (Sandbox Code Playgroud) 有没有办法在第一个事件触发后执行第二个事件?
在下面的示例中,我想在调用 touchmove 事件后使用滚动事件。
fromEvent(window, 'touchmove').pipe(
tap(() => this.scroll$.next(false),
debounceTime(100)
).subscribe(() => {
this.scroll$.next(true);
})
Run Code Online (Sandbox Code Playgroud) angular ×5
rxjs ×5
javascript ×4
image ×2
react-native ×2
animation ×1
async-await ×1
browser ×1
colors ×1
css ×1
datepicker ×1
dynamic ×1
firebase ×1
html ×1
kotlin ×1
performance ×1
promise ×1
rxjs6 ×1
state ×1
typescript ×1