From 6b5984408408801af9431012760d7400fe4fb9c5 Mon Sep 17 00:00:00 2001 From: Keegan Lillo Date: Thu, 16 Jun 2016 14:52:31 -0700 Subject: [PATCH] Fixed some straggling mentions of the old array behavior --- README.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c78e01b..347e009 100755 --- a/README.md +++ b/README.md @@ -899,7 +899,39 @@ cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000); | `Clay( [array] config, [function] customFn=null, [object] options={autoHandleEvents: true})`
`config` - an Array representing your config
`customFn` - function to be run in the context of the generated page
`options.autoHandleEvents` - set to `false` to prevent Clay from automatically handling the "showConfiguration" and "webviewclosed" events | `Clay` - a new instance of Clay. | | `.registerComponent( [ClayComponent] component )`
Registers a custom component. | `void`. | | `.generateUrl()` | `string` - The URL to open with `Pebble.openURL()` to use the Clay-generated config page. | -| `.getSettings( [object] response, [boolean] convert=true)`
`response` - the response object provided to the "webviewclosed" event
`convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `Object` - object of keys and values for each config page item with an `messageKey`, where the key is the `messageKey` and the value is the chosen value of that item. This method will do some conversions depending on the type of the setting. Arrays containing strings will have zeros inserted before each item. eg `['one', 'two']` becomes `['one', 0, 'two', 0]`. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0`. Pass `false` as the second parameter to disable this behavior | +| `.getSettings( [object] response, [boolean] convert=true)`
`response` - the response object provided to the "webviewclosed" event
`convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `Object` - object of keys and values for each config page item with an `messageKey`, where the key is the `messageKey` and the value is the chosen value of that item.

This method will do some conversions depending on the type of the setting. Arrays will use message key array syntax to make the values of each item in the array available as individual message keys. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0`. If the value is a number or an array of numbers and the optional property: "precision" is the power of precision (value * 10 ^ precision) and then floored. Eg: `1.4567` with a precision set to `3` will become `1456`. Pass `false` as the second parameter to disable this behavior. See the example below for how this all works | + +#### `.getSettings()` Example + +```javascript + +// webviewclosed response +{ + "favorite_food": {"value": [1, 0, 1]}, + "cool_things_enabled": {"value": true}, + "user_name": {"value": "Jane Doe"}, + "date_of_birth[0]": {"value": 1989}, + "date_of_birth[1]": {"value": 11}, + "date_of_birth[2]": {"value": 28}, + "rating": {"value": 3.5, "precision": 1}, +} + +// resulting converted values + +var messageKeys = require('message_keys'); + +messageKeys.favorite_food + 0 = 1; +messageKeys.favorite_food + 1 = 0; +messageKeys.favorite_food + 2 = 1; +messageKeys.cool_things_enabled = 1; +messageKeys.user_name = 'Jane Doe'; +messageKeys.date_of_birth + 0 = 1989; +messageKeys.date_of_birth + 1 = 11; +messageKeys.date_of_birth + 2 = 28; +messageKeys.rating = 35; + + +``` ---