Code Monkey home page Code Monkey logo

Comments (11)

back2dos avatar back2dos commented on June 1, 2024

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.

kevinresol avatar kevinresol commented on June 1, 2024

Well, this workaround looks soooo complicated... and wrapping the content in some extra div may make some css frameworks to fail...

from tink_state.

kevinresol avatar kevinresol commented on June 1, 2024

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.

back2dos avatar back2dos commented on June 1, 2024

If you give the swapper a key that should avoid replacing it.

from tink_state.

kevinresol avatar kevinresol commented on June 1, 2024

If you give the swapper a key that should avoid replacing it.

Yeah that's it. Great.

from tink_state.

back2dos avatar back2dos commented on June 1, 2024

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.

kevinresol avatar kevinresol commented on June 1, 2024

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.

kevinresol avatar kevinresol commented on June 1, 2024

Or just expose it and let user decide?

from tink_state.

back2dos avatar back2dos commented on June 1, 2024

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.

kevinresol avatar kevinresol commented on June 1, 2024

I will check if I can use that in InfiniteList to get rid of the cache field

from tink_state.

back2dos avatar back2dos commented on June 1, 2024

I'll just assume this works. Feel free to close otherwise ;)

from tink_state.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.