在阅读了几篇关于es6承诺有多么伟大以及为什么要实现它们的文章之后,我一直觉得我的所有(非平凡的)javascript函数都应该是promises.
事实上,在使用它们编写代码时我感觉很棒,因为我避免了厄运的三角形,看起来似乎得到了清晰简洁的代码.(它确实使执行的推理变得更加简单).
我无法找到的是:你什么时候不使用承诺?我什么时候避免使用它们?
更新:
虽然我已经看到了一些像API一致性这样的优点,但我还没有找到一个坚实的NO案例.Lux的答案表明,获取事件发射器的操作应该避免它们,因为重复的回调与promises不兼容.但我确实觉得答案仍然缺乏实质性的检查(正确)现在.
根据Trello官方文档(https://trello.com/c/IMVYmVG1/1458-webhooks),关于webhook有效负载,“当事件触发时,您将收到以下格式的JSON有效负载:
{
action: { ... }
model: { ... }
}
Run Code Online (Sandbox Code Playgroud)
但是我的webhook没有发布任何“动作”属性。
查看我的回调收到的参数:
Started POST "/trello_hooks/doing_callback" for 127.0.0.1 at 2015-02-27 11:29:04 +0100
Processing by TrelloHooksController#doing_callback as HTML
Parameters: {"model"=>{"id"=>"54efd4339c9ed81c24d64ced", "name"=>"Bureau", "desc"=>"", "descData"=>nil, "closed"=>false, "idOrganization"=>nil, "pinned"=>false, "url"=>"https://trello.com/b/C9Tlh6lw/bureau",
"shortUrl"=>"https://trello.com/b/C9Tlh6lw", "prefs"=>{"permissionLevel"=>"private", "voting"=>"disabled", "comments"=>"members", "invitations"=>"members", "selfJoin"=>false, "cardCovers"=>true, "cardAging"=>"regular", "calendarFeedEnabled"=>false, "background"=>"blue", "backgroundColor"=>"#0079BF", "backgroundImage"=>nil,
"backgroundImageScaled"=>nil, "backgroundTile"=>false, "backgroundBrightness"=>"unknown", "canBePublic"=>true, "canBeOrg"=>true, "canBePrivate"=>true, "canInvite"=>true}, "labelNames"=>{"green"=>"Merci Edgar", "yellow"=>"LBP", "orange"=>"Kismar", "red"=>"WhiteMark", "purple"=>"", "blue"=>"", "sky"=>"", "lime"=>"", "pink"=>"", "black"=>""}},
"trello_hook"=>{"action"=>"doing_callback", "model"=>{"id"=>"54efd4339c9ed81c24d64ced", "name"=>"Bureau", "desc"=>"", "descData"=>nil, "closed"=>false, "idOrganization"=>nil, "pinned"=>false, "url"=>"https://trello.com/b/C9Tlh6lw/bureau", "shortUrl"=>"https://trello.com/b/C9Tlh6lw", "prefs"=>{"permissionLevel"=>"private", "voting"=>"disabled", …Run Code Online (Sandbox Code Playgroud) 假设您有一个包含在 Django 应用程序后面运行的 User 对象的数据库,并且您希望使用它django-taggit来标记 User 对象,以便您可以使用一些方便的过滤来检索子组。
此外,您还有一个仪表板,您希望在其中显示有关已用标签的有趣统计信息,以收集有关用户中存在的子组的一些信息。
您将如何访问和显示有关 Django 应用程序中使用的前 X 个标签的信息?
如何仅访问用户对象已过滤子组的前 X 个标签?
django ×1
es6-promise ×1
filtering ×1
javascript ×1
node.js ×1
payload ×1
promise ×1
ruby ×1
trello ×1