Download the PHP package sparky-spa/sparky without Composer
On this page you can find all versions of the php package sparky-spa/sparky. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sparky
The tool to develop Single Page Applications on PHP
Easy to start, easy to use
HOW TO USE
Install
Run composer require sparky-spa/sparky
Setup config
Set up the settings
Endpoint ajax_uri
implementation
It has to support the next URIs
Also, use the function handleHttpRequest()
to implement the endpoints correctly
For POST <ajax_uri>/....
requests
For GET <ajax_uri>/{Sparky::NAME_MINI_JS}
request
Feel free to use the tool 😉
Back-end
Implement a Component
Let imagine, we have the component
Insert component into a page
The all next variants will work correctly
If you place a component to an additional namespace (e.g. User\ChatCheckerComponent
), use the next syntax
Component Actions
Calling order of a component actions
customAction
This is an action, which calls by emit
actions.
Return a string to skip the $component->render();
calling. The returned string will be a response onto an ajax request.
In the case, the action $component->beforeRendering();
will be skipped too. So, please, call it inside the $component->customAction();
, if it needs.
Views
Emit component action
onClick: emit action
It makes request to back-end to an action
onClick: init event
It doesn't make request to back-end but trig an event/action listeners only
Emit action
The time - is delay to an action will emit after the Sparky loading
Init component event
Action on a page/component load
The main different between spa:emit
and spa:event
is the last one inits an event listeners but not to call the component action on back-end
Bind Component property to HTML field
The component_property_name
has to be public property of a component
JavaScript
Sparky load events
It's important to use the load events, because it's a safety way to prevent the error Uncaught ReferenceError: Sparky is not defined
Events list
Inits once per a page load
SparkySpaSetConfig
- Sparky config could not be set up at the moment. Please do not use the event if you`re not sureSparkySpaBeforeInit
- the event after the config setting upSparkySpaInit
- the all Sparky elements have been initiated
Inits after a page loading and each time after a component receiving answer on an action request from back-end
SparkySpaLoad
- inits before a component events queue will be process.
Emit component action in JS
The next executions will call a component method
action_name
- it's a component method name, which will call. It also is an event_name
for listeners
data
- this is args list of action_name
method
callback
- it will execute after an emit request will be done and before a listener calling
Init component event
To init component event in JS
It also will not call a component method but inits the event listeners
Event/Action Listener in JS
Use the next things to listen an event
event_name
- it's a component method name, which was called
component_name
- a component name of an event.
event_data.response
- it will contain HTML body of response if an action (not event) was emitted quietly
Note Do not check a component
Reserved event names
sparky:update_binds
sparky:update_binds
- executes on a component property update by a bound tag.
This event pass an updated properties list to a listener
WARNING
Please, do not pass secure data into a Component's public property. It passes to front-end and could be readed in browser