What is the difference between a singleton collection or an instance in Titanium?

Alloy docs mention that you can have one or one instance of a collection. You define one way or another using the instance tag:

<Alloy>
    <Collection id="localLibrary" src="book" instance="true"/>
    <Window>
        <TableView id="table" />
    </Window>
</Alloy>

I understand the general idea of ​​a single instance vs instance ... but I do not understand the direct advantage / application in order to expose it to the controller anyway.

In particular, what is the difference between this controller code:

var library = Alloy.Collections.book;
library.fetch();

and this controller code:

var library = $.localLibrary;
library.fetch();

Does he say "capture everything" instead of "capture only this?"

Any clarification would be wonderful, tia.

+4
source share
1 answer

, Alloy.Collections.instance("book") singleton ( ...), , Alloy.Collections.book. Models.

? , , , , , TableView , - ...

:

var library = Alloy.Collections.book; // <Collection src="book"/>
    library.fetch();

:

var library = $.localLibrary; // <Collection id="localLibrary" src="book" instance="true"/>
    library.fetch();
+3

Source: https://habr.com/ru/post/1529732/


All Articles