Comments (7)
Not sure if you mean what I think you mean, but I really needed this feature and ember-cpm's computedPromise
just wasn't cutting it (due to an infinite loop bug and a state sharing bug).
Here's what I did:
computedTask = (depKeys..., fn) ->
computed (key) ->
unless @[key + "Task"]?
@[key + "Task"] = task =>
@[key + "TaskCurrentResult"] = yield fn.call @
@notifyPropertyChange key
.restartable()
for depKey in depKeys
@addObserver depKey, @, ->
@get(key + "Task").perform()
@get(key + "Task").perform()
@[key + "TaskCurrentResult"]
Then, I use this like so:
DS.Model.extend
comments: hasMany "comment", async: true
isApproved: computedTask "comments.lastObject", ->
@get "comments"
.then (comments) ->
comments.get("lastObject")
.then (comment) ->
comment.get("message") is "lgtm"
But yeah, it'd be great if ember-concurrency could have observable computed property feature. Also, if my implementation isn't too much cancer, I can do a pr if no one else is working on this already.
from ember-concurrency.
@foxnewsnetwork I was actually referring to RxJS Observables, of which I have (an unpublished) spike here: http://ember-concurrency.com/#/docs/examples/observables
I'm not sure I totally follow but are you saying you want a task to be performed when some observed property changes?
from ember-concurrency.
Yes, exactly that. The Task api already has an on
method to listen to events, but I wound up needing an observes
method to handle a lot of the ember-data async logic.
But lol, I guess that's another feature for another day.
from ember-concurrency.
@foxnewsnetwork yeah, I'm not ready to add that feature just yet until we've all had time to absorb the current API. There might just be another task-friendly approach to what you're trying to do that avoids the ugliness of observers.
from ember-concurrency.
@machty I'd love to see the observable integration in. Our ember app needs to poll our backend and an Observable would be perfect for this. We're also aiming to get a release of orbit.js out soon which uses Observables for realtime queries(rxjs under the hood), would be awesome if those could be unsubscribed automatically in components.
from ember-concurrency.
I have a similar need. I often use this pattern:
myPromiseComputedProperty: computed('a', 'b', function() {
const _this = this;
let prom = new Ember.RSVP.Promise(function(resolve, reject) {
let myVar = null;
myVar = _this.get('myTask').perform();
if(!myVar) {
reject("error");
} else {
resolve(myVar);
}
});
return DS.PromiseObject.create({ promise: prom });
}),
myTask: task(function * () {
...
})
It does not work with an Ember-Concurrency task. Maybe I have the wrong approach/antipattern. Happy to hear your take on it.
from ember-concurrency.
@20v100 you shouldn't need to wrap in a promise
let prom = this.get('myTask').perform();
return DS.PromiseObject.create({ promise: prom });
from ember-concurrency.
Related Issues (20)
- v2 addon conversion? HOT 1
- [Bug] 2.3.2 broke `observes` modifier HOT 12
- Migration guide for task groups HOT 3
- The new API doesn't seem to work with ember-cli-code-coverage HOT 7
- Minor typo in 2.3.2 release notes HOT 1
- `dropTask` not properly typed HOT 3
- TaskCancelation: TaskInstance XXX was canceled because undefined HOT 1
- Test helpers for enqueued tasks
- Use "real" symbol instead of string for yieldableSymbols HOT 2
- resetState: true does not reset performCount
- Use same types for return and arg HOT 2
- Plans for Ember 4.x migration HOT 1
- Not working in Ember 4.8+ HOT 3
- Ember 4.8 types preview issue HOT 1
- Decorators in JavaScript project HOT 1
- Typescript question for creating custom task modifiers HOT 1
- Docs code examples gone in the latest version
- Docs recommend using a private Ember API for test cleanup HOT 3
- 3.0.0 doesnโt include #512? HOT 2
- Perfrom helper in Typescript HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-concurrency.