Skip to content

Commit

Permalink
Merge pull request dotnet#52 from madewithkoji/gatsby-ascii-doc
Browse files Browse the repository at this point in the history
Minor updates to user defaults
  • Loading branch information
rasienko committed Aug 24, 2020
2 parents e0666a2 + 23e8591 commit c78e87f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/asciidoc/reference/packages/withkojiUserDefaults.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ The @withkoji/user-defaults package provides
a secure interface for accessing permissioned user data across all Koji templates.
//end::description[]

A template can request data with a reserved key, for the user's Koji profile data, or with a user key that is defined in any template on Koji, for additional preferences.
A template can request data with a reserved key, for the user's Koji profile data, or with a user key from any template on Koji, for additional preferences.
This data can then be used to autofill values and personalize experiences.
For example, automatically enter the user's name in a leaderboard, or display the user’s avatar in a game.

Keys defined in any template are available in a global, unscoped namespace and do not need to be registered.
When a value is requested that is not a reserved key, Koji checks whether the user has entered a value for it, either on the current template or on a different template.
Keys requested from any template are available in a global, unscoped namespace and do not need to be registered.
When a request does not use a reserved key, Koji checks whether the user has entered a value for the requested key, either on the current template or on a different template.
If not, the user is prompted to submit a value and allow it to be saved for later reuse.
This method enables users to own and manage their data in a transparent, portable way, rather than relying on cookies or other measures.

Expand Down Expand Up @@ -42,19 +42,19 @@ const kojiUserDefaults = new KojiUserDefaults();
[.hcode, id=".onConnect", reftext="onConnect"]
=== .onConnect(handler[isConnected])

Listens to the connection state to enable access to permissioned user data.
Listens to the user's login state to enable access to permissioned user data.

==== Parameters

* `handler` – Function to handle requests for user data.
* `isConnected` – Boolean that indicates whether the data bridge is connected.
* `isConnected` – Boolean that indicates whether the user is logged in to Koji.

==== Example

[source,javascript]
----
kojiUserDefaults.onConnect((isConnected) => {
// If connected, get user name
// If logged in, get user name
if (isConnected) {
kojiUserDefaults.get('profile.username', (success, key, value) => {
console.log(success, key, value);
Expand All @@ -70,10 +70,12 @@ Gets a specified piece of user data and invokes a callback function to handle th

==== Parameters

* `key` – String, key of the user data to retrieve. See <<_keys>>.
* `key` – String, key of the user data to retrieve.
See <<_keys>>.
* `handler` – Function to handle the results of the data request.
* `success` – Boolean that indicates whether the request was successful.
* `value` – String, value of the user data, if the request was successful. For an unsuccessful request, the value is `undefined`.
* `value` – String, value of the user data, if the request was successful.
For an unsuccessful request, the value is `undefined`.

==== Example

Expand Down Expand Up @@ -104,8 +106,8 @@ The following *reserved keys* can be used to access data from the user's Koji pr
* `profile.profilePicture`
* `profile.reputation`

User keys defined in any other template represent string values in an unscoped, portable, global storage.
For example, you could define a key in your template called `user.favoriteColor`, and then reuse that value in any other Koji template.
Additionally, any template can request user data, and the specified key will be used to represent string values in an unscoped, portable, global storage.
For example, you could request a key in your template called `user.favoriteColor`, and then reuse that value in any other Koji template.

== Related resources

Expand Down

0 comments on commit c78e87f

Please sign in to comment.