UNPKG

@bemedev/app-react

Version:
1 lines 954 B
{"version":3,"file":"getSnapshot.cjs","sources":["../../src/utils/getSnapshot.ts"],"sourcesContent":["import type {\n AnyMachine,\n ContextFrom,\n InterpreterFrom,\n} from '@bemedev/app-ts';\nimport { dequal } from 'dequal';\nimport type { RefObject } from 'react';\nimport type { State } from '../types';\n\nexport function getSnapshot<const M extends AnyMachine = AnyMachine>(\n service: InterpreterFrom<M>,\n ref: RefObject<State<ContextFrom<M>>>,\n) {\n const snapShot = service.getSnapshot();\n\n const check = dequal(snapShot, ref.current);\n if (check) return ref.current;\n\n ref.current = snapShot;\n return ref.current;\n}\n"],"names":["dequal"],"mappings":";;;;AASgB,SAAA,WAAW,CACzB,OAA2B,EAC3B,GAAqC,EAAA;AAErC,IAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE;IAEtC,MAAM,KAAK,GAAGA,aAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;AAC3C,IAAA,IAAI,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO;AAE7B,IAAA,GAAG,CAAC,OAAO,GAAG,QAAQ;IACtB,OAAO,GAAG,CAAC,OAAO;AACpB;;;;"}