# See the License for the specific language governing permissions and
# limitations under the License.
-# Simple data storage services
+# Key/value storage services
#
-# The implementation varies per platform.
+# The main services is `App::data_store`, a `DataStore` holding any
+# serializable Nit object.
module data_store
import app_base
import ios::data_store is conditional(ios)
redef class App
+
# Services to store and load data
+ #
+ # ~~~
+ # import app::ui
+ # import app::data_store
+ #
+ # class MyWindow
+ # super Window
+ #
+ # var state = "Simple string or any serializable class"
+ #
+ # redef fun on_save_state do app.data_store["state"] = state
+ #
+ # redef fun on_restore_state
+ # do
+ # var state = app.data_store["state"]
+ # if state isa String then self.state = state
+ # end
+ # end
+ # ~~~
var data_store = new DataStore is lazy
end
# Simple data storage facility
+#
+# Write values with `[]=` and read with `[]`.
+# ~~~
+# import linux::data_store # Needed for testing only
+#
+# class A
+# serialize
+#
+# var b = true
+# var f = 1.234
+# end
+#
+# var data_store = new DataStore
+# data_store["one"] = 1
+# data_store["str"] = "Some string"
+# data_store["a"] = new A
+#
+# assert data_store["one"] == 1
+# assert data_store["str"] == "Some string"
+# assert data_store["a"].as(A).b
+# assert data_store["a"].as(A).f == 1.234
+# assert data_store["other"] == null
+# ~~~
+#
+# Set to `null` to clear a value.
+# ~~~
+# data_store["one"] = null
+# assert data_store["one"] == null
+# ~~~
class DataStore
# Get the object stored at `key`, or null if nothing is available
# limitations under the License.
# HTTP request services: `AsyncHttpRequest` and `Text::http_get`
+#
+# ~~~nitish
+# import app::http_request
+#
+# class MyHttpRequest
+# super AsyncHttpRequest
+#
+# redef fun uri do return "http://example.com/"
+#
+# redef fun on_load(data, status) do print "Received: {data or else "null"}"
+#
+# redef fun on_fail(error) do print "Connection error: {error}"
+# end
+#
+# var req = new MyHttpRequest
+# req.start
+# ~~~
module http_request
import app_base
fun after do end
end
-# Minimal implementation of `AsyncHttpRequest` where `uri` is an attribute
+# Simple `AsyncHttpRequest` where `uri` is an attribute
+#
+# Prints on communication errors and when the remote server returns an
+# HTTP status code not in the 200s.
#
-# Prints on communication errors and when the server returns an HTTP status code not in the 200s.
+# This class can be instantiated to execute a request where the response is
+# ignored by the application. Alternatively, it can be subclassed to implement
+# `on_load`.
#
# ~~~nitish
# var request = new SimpleAsyncHttpRequest("http://example.com")
# See the License for the specific language governing permissions and
# limitations under the License.
-# Portable UI controls from mobiles apps
+# Portable UI controls for mobiles apps
+#
+# ~~~
+# import app::ui
+#
+# class MyWindow
+# super Window
+#
+# var layout = new ListLayout(parent=self)
+# var lbl = new Label(parent=layout, text="Hello world", align=0.5)
+# var but = new Button(parent=layout, text="Press here")
+#
+# redef fun on_event(event) do lbl.text = "Pressed!"
+# end
+#
+# redef fun root_window do return new MyWindow
+# ~~~
module ui
import app_base