new ChildAPI(url)
Initialize a child frame using the given URL.
Parameters:
Name | Type | Description |
---|---|---|
url |
string |
URL that is used as 'src' for the iframe |
Properties:
Name | Type | Description |
---|---|---|
url |
string |
iFrame URL |
msg_count |
number |
Incrementing message ID |
responses |
object |
Dictionary of request Promises waiting for their responses |
msg_bus |
object |
Postmate instance |
handshake |
promise |
Promise that is waiting for connection confirmation |
class_name |
string |
iFrame's unique class name |
loaded |
boolean |
Indicates if iFrame successfully loaded |
Methods
(async) connect() → {this}
Wait for handshake to complete and then attach response listener.
(async, private) request(method, name, data) → {*}
Internal method that wraps requests in a timeout.
Parameters:
Name | Type | Description |
---|---|---|
method |
string |
Internally consistent Postmate method |
name |
string |
Function name or property name |
data |
* |
Variable input that is handled by child API |
(async) run(method, …args) → {*}
Call an exposed function on the child instance and wait for the response.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
method |
string |
Name of exposed function to call |
|
args |
* |
<repeatable> |
Arguments that are passed to function |
(async) set(key, value) → {boolean}
Set a property on the child instance and wait for the confirmation. Properties set that way
can be accessed as properties of this
in the functions passed via listen() to the parentAPI.
Essentially, it is a shortcut to remember some state instead of having to write a method to
remember some state. Example child.set("development_mode", true)
vs
child.call("setDevelopmentMode", true)
. The latter requires you to define
setDevelopmentMode
on the child model where the former does not require any
pre-configuration.
Parameters:
Name | Type | Description |
---|---|---|
key |
string |
Property name |
value |
* |
Property value |