-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Update README with base information about SDK usage #58
Conversation
README.md
Outdated
The SDK can be initialized in two different ways depending on your needs. | ||
|
||
### Synchronous | ||
You can fetch the data file content on your own and just pass it via options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single word datafile
.
```swift | ||
import FeaturevisorSDK | ||
|
||
let datafileContent: DatafileContent = ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any handy function for converting JSON string to DatafileContent? something like:
let datafileContent = DatafileContent.fromString("...stringified json here...")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today it can be achieved like below but anyway, such a direct method will be useful. Will handle it under a different PR.
guard let data = datafileJSON.data(using: .utf8) else { return }
let datafileContent = try? JSONDecoder().decode(DatafileContent.self, from: data)
README.md
Outdated
var options: InstanceOptions = .default | ||
options.datafile = datafileContent | ||
|
||
let featurevisor = try createInstance(options: options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the website, I have tried using f
as the instance variable everywhere.
you don't have to change anything, only mentioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be consistent across our SDKs as much as possible.
README.md
Outdated
|
||
var options: InstanceOptions = .default | ||
options.handleDatafileFetch = { datafileUrl in | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we supposed to return an object following DatafileContent
type here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, as handleDatafileFetch
is a following type public typealias DatafileFetchHandler = (_ datafileUrl: String) -> Result<DatafileContent, Error>
README.md
Outdated
"userId": .string("123") | ||
] | ||
|
||
let variation = sdk.getVariation(featureKey: featureKey, context: context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idea for future: we may consider using the _
thingy in Swift, so we don't always have to pass the argument names manually.
we could then do:
let variation = sdk.getVariation(featureKey, context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was fighting with my thoughts about this some time ago trying to find the answer to what will be more obvious for people using it. Will take it as an improvement and handle under different PR.
README.md
Outdated
"country": .string("nl") | ||
] | ||
|
||
let isEnabled = sdk.isEnabled(featureKey: featureKey, context: context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth clarifying that sdk
is the SDK instance here. we may want to use the same instance variable name consistently throughout this whole README.
README.md
Outdated
|
||
#### JSON object | ||
```swift | ||
sdk.getVariableJSON(featureKey: FeatureKey, variableKey: VariableKey, context: Context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does Swift support generics? and if yes, should this method accept a type as a generic for the expected returned output?
like:
sdk.getVariableJSON<MyTypeHere>(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we have generics :). Something like below is enough for the compiler to know the type:
let variable: MyAwesomeType = sdk.getVariableJSON(featureKey: "feature_key", variableKey: "variable_key", context: context)
Will update the readme to be more precise.
README.md
Outdated
``` | ||
|
||
### Logging | ||
By default, Featurevisor will log logs to the for `warn` and `error` levels. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to the "console"? I don't know what's the console equivalent (from browser and Node.js environments) in Swift.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking about the IDE's console output window. Will update the description
let logger = createLogger( | ||
levels: [.error, .warn, .info, .debug], | ||
handle: { level, message, details in ... }) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth showing how the logger
instance is passed to options
when creating the SDK instance.
No description provided.