Advertisement
pharmokan

State Knockout Component

Jun 2nd, 2021
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. construct:
  2. state.state = JSON.parse(window.localStorage.getItem('acme_products_state')) || stateReset()
  3. is localstorage set ? state.direction = ls.direction | state.direction = true && setState('direction',true)
  4. ===
  5.  
  6. toggleDirection() state.direction = !state.direction setState('direction',!state.direction) $.event onClick $('#acme_sorter')
  7. getDirectionValue(): 'ASC' = true | 'DESC' = false !state.direction
  8. getDirectionTitle(): 'ascending' | 'descending'
  9. setFlag(bool): true | false
  10. toggleFlag(): state.flag = !state.flag
  11. isFlagged(): state.flag true | false
  12. isLoading(): state.loading true | false
  13. isValid(): state.valid true|false
  14. setValid(bool) : true|false
  15. setLoading(bool): bool ? state.loading = !state.loading
  16. setIsLoading(bool): true | false
  17. setMsg(str): str.length > 0 ? state.msg = str && setFlag(true) : null
  18. getMsg(): isFlagged() ? state.msg : null
  19. setDirection(direction): localstorage.set. state.direction = !state.direction
  20. getPostData(): object {price_from : price[from], price_to: price[to],direction}
  21. getFormData(): object {price_from : price[from], price_to: price[to],direction}
  22. resetState(): {price_from = 1, price_to = 5, direction = true, msg = '', flag = false, loading = false,}
  23. resetPrice(): {price_from = 1, price_to = 5}
  24. resetDirection(): state.direction setState('direction',true)= true
  25. isDirectionDefault(): state.direction = true ? true : false //means direction is desc
  26. setPostData(): object { price_from,price_to,direction }
  27. setFormData(): object { price_from,price_to,direction }
  28. getGqlQuery(): object //TODO
  29. getSearchCriteriaBuilder() object //TODO
  30. getPriceFrom(): int state.price.from
  31. getPriceTo(): int state.price.to
  32. setPriceFrom(priceFrom): state.price.from =
  33. setPriceTo(priceTo) state.price.to =
  34. setPrice(priceFrom,priceTo) state.price.to = priceFrom| state.price.from = priceTo
  35. getPrevState(): object
  36. setPrevState(obj): prevState = { ..state }
  37. getCurrentState(): self|this
  38. setStateSnapshot(state): setPrevState(state)
  39. getState(key = null): window.localstorage.getItem(key) any key{ direction|price_from|price_to|directionValue|directionTitle|msg|flag|loading|valid } | key == null ? this(class) : null
  40. setState(key,data): prevState = state && state = state[key] = newState localStorage.setItem('acme_products_state' = JSON.stringify(newState)
  41.  
  42. before function
  43. setCall(data): setState(key,data)
  44. after function
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement