Comments (11)
Good idea. It will be a breaking change, so I'll have to think about how to time it.
For now I would suggesting using something like this somewhat hideous higher level component to deal with not only that, but also keep around a copy of the old view for making nice transitions. Note that hxx allows you to use it like so:
var user:Observable<Promised<{ name:String }>> = ...;
coconut.Ui.hxx('
<Swapper class="something" data={user}>
<renderData>
<p>Hello {name}</p>
</renderData>
</Swapper>
');
//alternatively (if you wish to name the state):
coconut.Ui.hxx('
<Swapper class="something" data={user}>
<renderData {...u}>
<p>Hello {u.name}</p>
</renderData>
</Swapper>
');
If you don't name the argument (as in the first example), you can refer to it as $
.
from tink_state.
Well, this workaround looks soooo complicated... and wrapping the content in some extra div may make some css frameworks to fail...
from tink_state.
And if I somehow access the promised data before the swapper, the swapper stack will be gone. Probably because the swapper has been replaced by a new instance.
function render() '
<div class="ui container vertical segment">
<div class=${"ui icon input" + (search.results == Loading ? " loading" : "")}>
<input oninput=${onInput.bind(search)} placeholder="搜尋"/>
<i class="search icon"/>
</div>
<Swapper class="" data=${search.results}>
<renderData {...d}>
${Std.string(d)}
</renderData>
</Swapper>
</div>
';
Removing + (search.results == Loading ? " loading" : "")
will make it work as expected
from tink_state.
If you give the swapper a key that should avoid replacing it.
from tink_state.
If you give the swapper a key that should avoid replacing it.
Yeah that's it. Great.
from tink_state.
Ok, uhm, I wanted to do something about it, but it led me to wonder, what do we do in PromisedTools.next if a previous value is available? Rather f(prev)
or stick with the Promise.NEVER
?
from tink_state.
Well I guess it should be f(prev)
, or even better, a cached value of that (because it may not have resolved yet).
But since the function itself is pure and has no memory. I think f(prev)
is the way....
from tink_state.
Or just expose it and let user decide?
from tink_state.
This is now supported in a slightly different way. You can define computations as Option<T>->T
and Option<T>->Promise<T>
in which case the option will contain the last value and the last Done
value respectively.
In coconut.data
this is currently supported via $last
(better ideas are highly welcome).
It doesn't smoothly cover all the cases of having the previous value for Promised
, i.e. if you consume an external Promised
you have to resort to this:
@:external var data:Promised<Foo>;
@:loaded var withPrevious:Foo = switch [data, $last] {
case [Done(v), _] | [_, Some(v)]: Success(v);
case [Failed(e), _]: e;
case [Loading, _]: Promise.NEVER;
}
So, you think this will this work for you? ^^
from tink_state.
I will check if I can use that in InfiniteList to get rid of the cache
field
from tink_state.
I'll just assume this works. Feel free to close otherwise ;)
from tink_state.
Related Issues (20)
- Granular observation in Map/Array HOT 2
- Change is not remembered somehow HOT 1
- ObservableMap.observe should return ObservableMapView HOT 1
- What API replaces observableLength and observableValues? HOT 3
- Suspend async computation when observable goes out of use.
- Add `ObservableObject.isConstant` HOT 1
- ObservableArray exposes internal methods due to `@:forward`
- Issue with SignalObservable(?)
- LinkObject import is missing in the Binding.hx HOT 4
- Add js-compat flag.
- Reduce allocations.
- Async Observable.
- Allow swapping computation in auto observable.
- Obervable.ofPromise does not fire binding? HOT 3
- Exception catching mode HOT 1
- early break in AutoObservable s.hasChanged check can trigger multiple recalculations HOT 2
- async auto-observable value not being updated properly when not bound (only on `v1` branch) HOT 1
- Add State.update HOT 2
- mapAsync broken?
- Sometimes direct bindings run before all observables are invalidated.
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 tink_state.