- Snack
- addLogListener
- addStateListener
- getDownloadURLAsync
- getPreviewAsync
- getState
- getStateAsync
- reloadConnectedClients
- saveAsync
- sendCodeChanges
- setCodeChangesDelay
- setDescription
- setDeviceId
- setDisabled
- setFocus
- setName
- setOnline
- setSDKVersion
- setUser
- updateDependencies
- updateFiles
- uploadAssetAsync
+ new Snack(options
: SnackOptions): Snack
Name | Type |
---|---|
options |
SnackOptions |
Returns: Snack
▸ addLogListener(listener
: SnackLogListener): SnackListenerSubscription
Adds a callback for listening for any client generated log messages.
example
const unsubscribe = Snack.addLogListener((log) => {
console.log('log message received: ', log);
});
unsubscribe(); // Remove listener
Name | Type |
---|---|
listener |
SnackLogListener |
Returns: SnackListenerSubscription
▸ addStateListener(listener
: SnackStateListener): SnackListenerSubscription
Adds a callback for listening for any state changes.
example
const unsubscribe = Snack.addStateListener((state, prevState) => {
if (state.name !== prevState.name) {
console.log('name changed: ', state.name);
}
});
Snack.setName('unforgiven orange'); // // Make a change to the state
unsubscribe(); // Remove listener
Name | Type |
---|---|
listener |
SnackStateListener |
Returns: SnackListenerSubscription
▸ getDownloadURLAsync(saveOptions?
: SnackSaveOptions): Promise<string>
Gets the URL at which the Snack can be downloaded as a zip file. Will automatically save the Snack if it contains unsaved changes.
Name | Type |
---|---|
saveOptions? |
SnackSaveOptions |
Returns: Promise<string>
▸ getPreviewAsync(): Promise<SnackConnectedClients>
Requests a preview from the connected clients.
The previews are returned in the previewURL
field of each connectedClient.
Returns: Promise<SnackConnectedClients>
▸ getState(): SnackState
Returns the current state of the Snack. This includes files, dependencies and other meta-data about the Snack.
Returns: SnackState
▸ getStateAsync(): Promise<SnackState>
Waits for any pending operations such as running dependencies resolutions before returning the state.
Returns: Promise<SnackState>
▸ reloadConnectedClients(): void
Reloads all connected clients.
Note: During the reload proces, clients may get disconnected which
causes the connectedClient to disappear and re-appear. The reloadTimeout
option in the constructor can be used to keep connectedClients "alive"
during the reload process.
Returns: void
▸ saveAsync(options?
: SnackSaveOptions): Promise<{ hashId: undefined | string ; id: string ; url: string = saveURL ; snackId: undefined | string ; accountSnackId: undefined | string ; }>
Uploads the current code to Expo's servers and return a url that points to that version of the code.
Name | Type |
---|---|
options? |
SnackSaveOptions |
Returns: Promise<{ hashId: undefined | string ; id: string ; url: string = saveURL ; snackId: undefined | string ; accountSnackId: undefined | string ; }>
▸ sendCodeChanges(): void
Sends any pending code changes to the connected clients. No changes are send if all clients are already up to date.
Returns: void
▸ setCodeChangesDelay(delay
: number): void
Sets the delay that is used before sending code updates to the connected clients. Use this method to set the "debounce" timeout to use for sending code changes over pubnub.
-1 = Disable automatic sending of code changes (use `sendCodeChanges` to trigger the send)
0 = Code changes are sent immediately to the connected clients
1..n = Code changes are debounced and sent after the wait time
Name | Type | Description |
---|---|---|
delay |
number | Timeout in milliseconds (or -1 to disable automatic code updates) |
Returns: void
▸ setDescription(description
: string): void
Sets the description of the Snack.
Name | Type |
---|---|
description |
string |
Returns: void
▸ setDeviceId(deviceId?
: undefined | string): void
Sets the device-id of an Expo client. When set and online
is true, causes this
Snack to appear on the "Recently in Development" section of that Expo client.
Name | Type |
---|---|
deviceId? |
undefined | string |
Returns: void
▸ setDisabled(disabled
: boolean): void
Enables or disables the Snack.
When disabled, no uploads or dependency resolve operations are performed.
Name | Type |
---|---|
disabled |
boolean |
Returns: void
▸ setFocus(): void
Sets the focus to this Snack.
Causes this Snack to be moved to the top of the "Recently in Development" list in the Expo client.
Returns: void
▸ setName(name
: string): void
Sets the name of the Snack.
Name | Type | Description |
---|---|---|
name |
string | E.g. "conspicious orange" |
Returns: void
▸ setOnline(enabled
: boolean): void
Makes the Snack available online.
When online, a pubnub channel is created to which clients can connect.
Name | Type |
---|---|
enabled |
boolean |
Returns: void
▸ setSDKVersion(sdkVersion
: SDKVersion): void
Sets the Expo SDK version.
Name | Type | Description |
---|---|---|
sdkVersion |
SDKVersion | Valid SDK version (e.g. "38.0.0") |
Returns: void
▸ setUser(user?
: SnackUser): void
Sets the associated user account.
When set and online
is true, causes this Snack to appear on the
"Recently in Development" section of all Expo clients that are signed
in with that account.
Name | Type |
---|---|
user? |
SnackUser |
Returns: void
▸ updateDependencies(dependencies
: { [name:string]: SnackDependency | null; }): void
Updates dependencies.
Use this method to add/remove/update dependencies.
To remove a dependency specify null
as the value of the key/value pair.
example
const Snack = new Snack({
dependencies: {
'react-native-paper': '~2.0.0'
}
});
// Add dependency
Snack.updateDependencies({
'expo-font': '9.0.0'
});
// Remove dependency
Snack.updateDependencies({
'expo-font': null
});
Name | Type |
---|---|
dependencies |
{ [name:string]: SnackDependency | null; } |
Returns: void
▸ updateFiles(files
: { [path:string]: SnackFile | null; }): void
Updates code or asset files.
Use this method to add/remove/update files and upload assets.
To remove a file specify null
as the value of the file.
example
const Snack = new Snack({
files: {
'App.js': { type: 'CODE', contents: 'console.log("hello world!");' },
'data.json': { type: 'CODE', contents: '{}' },
}
});
// Add or update files
Snack.updateFiles({
'App.js': {
type: 'CODE',
contents: 'console.log("Hello Snack!");'
}
});
// Upload an asset
Snack.updateFiles({
'assets/logo.png': {
type: 'ASSET',
contents: file // File, Blob or FormData
}
});
// Add a pre-uploaded asset
Snack.updateFiles({
'assets/expo.jpg': {
type: 'ASSET',
contents: 'https://mysite/expo.jpg'
}
});
// Remove files
Snack.updateFiles({
'data.json': null,
'assets/expo.jpg': null
});
Name | Type |
---|---|
files |
{ [path:string]: SnackFile | null; } |
Returns: void
▸ uploadAssetAsync(contents
: File | Blob | FormData): Promise<string>
Helper function that uploads an asset and returns its url.
Name | Type |
---|---|
contents |
File | Blob | FormData |
Returns: Promise<string>