Docs Log in Sign up

Docs For developers Package reference

Package reference

Everything the scrawlee package offers, with any framework or none.

Install

The package has no dependencies and loads nothing until your first call. Without a bundler, the same code is served by Scrawlee.

npm install scrawlee

import { cloud } from 'scrawlee'

<!-- without a bundler -->
<script type="module">
  import { cloud } from 'https://www.scrawlee.com/sdk/v1.js'
</script>

cloud

cloud.ready()Connects and resolves with { mode, inside, signedIn, user, access, config }. user is { id, name } or null.
cloud.me, cloud.statusThe same, kept up to date, and the connection: online, offline, read-only or unavailable.
cloud.ask()Opens the consent panel and resolves with the answer.
cloud.on(event, fn)status, access (choices changed), erased (the person erased their data), error. Returns the way to stop.
cloud.data(name)A value of scrawlee.yml.
cloud.room(kind)A kind of room of scrawlee.yml.
cloud.configure(options)Before the first call: mode: 'local', scrawl (the id, outside scrawlee.me), config (local mode).

cloud.data(name)

get(), get(key), get({ user })The value now: a map entry, or someone else's public value (their id).
set(value), set(key, value)Writes it, following the rules.
add(n), add(key, n)Adds to a number, negative to take away.
delete(), delete(key)Back to the default.
watch(fn, { key, user })Calls fn now and on every change. A map without key gets its entries and the change.
entries({ after, limit })A map's entries by key, 100 at most, with next.
ranking({ limit })A ranked public number: entries and the person's own place, me.
subscribe(fn)The Svelte store contract.

cloud.room(kind)

join(), join(code)A room with space left, or the one a code names. Resolves with the room.
room.members, room.me[{ id, name }], kept up to date.
room.send(type, data, { to })To everyone else, or to one member.
room.on(type, fn)A message type: fn(data, from). Also join, leave, members, state, reset, error, and message for every type.
room.stateget, set, add, delete, watch(name, fn), all().
room.leave()Leaves the room.

Errors

Every refusal rejects with a CloudError. Check its code, which stays the same across versions, rather than its message.

not_signed_in, no_accessSigned out, or the person did not allow saving.
read_only, unavailableOpened outside Scrawlee, or nothing to talk to.
ruleA rule refused it; details.rule says which: write, once, increase, decrease, step_max, min, max, max_entries, who.
invalidThe value does not match its type.
rate_limitedToo fast; retryAfter gives the seconds to wait.
quota, busy, fullStorage full, Scrawlee busy, or too many people connected.
bannedThe creator removed this person from the Scrawl's cloud data.
unknown_variable, unknown_room, unknown_messageNot declared in scrawlee.yml.
room_full, offline, timeoutThe room is full, or Scrawlee did not answer.

React, Vue and Svelte

useCloud(name) gives the value, kept up to date: a value in React, a ref in Vue. useCloudMe() gives cloud.me. In Svelte, a value is a store. Pages rendered on a server or at build time can import the package: it only connects in the browser.

import { useCloud } from 'scrawlee/react'   // or 'scrawlee/vue'
const best = useCloud('best')

<!-- Svelte -->
<script>
  import { cloud } from 'scrawlee'
  const best = cloud.data('best')
</script>
{$best}

Game engines

Engines that export to the web (Godot, Unity, GameMaker and others) can call the package from their HTML page through their JavaScript bridge. Ready-made modules for engines are planned.