Skip to content

Instantly share code, notes, and snippets.

View behnamazimi's full-sized avatar

Behnam behnamazimi

View GitHub Profile
@behnamazimi
behnamazimi / ServiceWrapper.queue.js
Created June 2, 2020 18:21
ServiceWrapper.queue.js
// this will fire immediately after adding to the queue
new ClientHandler({url: "https://reqres.in/api/users"})
.fire({parallel: true})
.then(res=> {
//...
})
// this will for its turn on queue
new ClientHandler({url: "https://reqres.in/api/users"})
@behnamazimi
behnamazimi / ClientHandler.setClient.js
Created June 2, 2020 18:21
ClientHandler.setClient.js
new ClientHandler(clientConfig)
.setClient(manualClient)
.setHook(HOOKS.BEFORE_RESOLVE, res => res.body) // get result and return the data property
.fire({parallel: true})
.then(res=> {
//...
})
@behnamazimi
behnamazimi / ServiceWrapper.setHook.js
Created June 2, 2020 18:20
ServiceWrapper.setHook.js
ServiceWrapper
// get result and return the data property
.setHook(HOOKS.BEFORE_RESOLVE, res => res.data)
// this method will call on all successes.
.setHook(HOOKS.AFTER_SUCCESS, res => {
console.log(res);
});
@behnamazimi
behnamazimi / ServiceWrapper.init.js
Created June 2, 2020 18:19
ServiceWrapper.init.js
ServiceWrapper
.init({
// `client` is the function that call inside `ClientHandler`
client: axios,
// `queue` is for determining that your service wrapper should active queue or not
queue: true,
// if this will be true, queue will log details in different stages
queueLogs: true,
@behnamazimi
behnamazimi / ClientHandler.fire.js
Last active June 2, 2020 18:19
collective service wrapper medium gist
new ClientHandler({url: "https://reqres.in/api/users"})
.fire()
.then(res => {
// handle result
console.log("users fetched");
})
.catch(err => {
/// handle error
console.log(err);
})
@behnamazimi
behnamazimi / example.logs
Created June 2, 2020 16:43
log result for collective service wrapper full example
+ ADDED: 1__glmag
* FIRED: 1__glmag [type: pending]
+ ADDED: 2__bgvrg
+ ADDED: 3__8jlr8
* FIRED: 3__8jlr8 [type: parallel]
- REMOVED: 1__glmag
* FIRED: 2__bgvrg [type: pending]
users fetched
- REMOVED: 3__8jlr8
user 3 fetched ==> this service was parallel
@behnamazimi
behnamazimi / js-service-wrapper.example.js
Last active June 6, 2020 17:56
Full exmaple of js service wrapper
const {ServiceWrapper, ClientWrapper, HOOKS} = require("js-service-wrapper");
ServiceWrapper
.init({
client: axios,
queue: true,
queueLogs: true,
})
.setResolveValidation(res => res.status === 200)
.setHook(HOOKS.BEFORE_RESOLVE, res => res.data)
@behnamazimi
behnamazimi / escape-loading-animation.html
Created May 3, 2020 09:28
HTML of escape loading animation
<div class="loading-container">
<div class="box-loading">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>
@behnamazimi
behnamazimi / escape-loading-animation.scss
Created May 3, 2020 09:27
Styles of escape loading animation
$duration: 1;
$box-number: 5;
$box-size: 1.5rem;
$box-gap: .7rem;
$primary-color: #039be5;
@keyframes moving {
0%, 5% {
left: 0;
background-color: $primary-color;
@behnamazimi
behnamazimi / jodit-react-component.js
Last active May 22, 2020 07:55
React component for Jodit HTML editor, module lazy loading support.
/**
* React component for Jodit HTML editor
* + Jodit module lazy loading support.
* + Debounce for change event to improve performance
*/
import React, {useEffect, useRef, forwardRef, useLayoutEffect, useMemo} from 'react'
import * as PropTypes from 'prop-types'
import 'jodit/build/jodit.min.css'
let CHANGE_DEBOUNCE_FLAG;