You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importxsfrom'xstream';import{run}from'@cycle/xstream-run';import{makeCookieDriver}from'cyclejs-cookie';functionmain({cookie}){constcookieChangeSource$=xs.periodic(1000);constcookieValue$=cookie.get('MyCookie');// just for print debugconstnoop=()=>undefined;cookieValue$.debug('cookie current value').addListener({next: noop,error: noop,complete: noop,});return{cookie: cookieChangeSource$.map((counter)=>({key: 'MyCookie',value: 'cookieValue-'+counter,settings: {expires: 30,// expiring in 30 days}}))};};run(main,{cookie: makeCookieDriver()});
Api
Library export only one function: makeCookieDriver
decode - set cookie.decode attribute, check cookie_js documentation for details.
cookieDriver(sink$)
$sink - driver assumes that sink$ is stream of cookie setter objects. it interprete cookie setter object and set new cookie (or delete if cookie value is undefined).
Returning cookies observables functions object {get(), all()}.
get(cookieName) - returning stream of cookie cookieName changes, initiated by current cookie value
all() - returning stream of all cookies object changes, initiated by starting cookies object
cookie setter object
Driver assumes following objects on it $sink:
{key: 'cookieName',value: 'cookieValue',// if undefined, cookie will be deletedoptions: {..}}